2015-07-10 06:01:56 -07:00
|
|
|
/**
|
2019-03-29 06:11:13 -07:00
|
|
|
* @file efi_gpio.h
|
2017-04-21 10:36:51 -07:00
|
|
|
* @brief EFI-related GPIO code
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
* @date Sep 26, 2014
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2019-12-11 14:48:55 -08:00
|
|
|
|
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2019-07-05 16:00:44 -07:00
|
|
|
#include "io_pins.h"
|
2019-09-19 18:41:52 -07:00
|
|
|
#include "engine_configuration.h"
|
2022-09-07 16:35:52 -07:00
|
|
|
#include "injection_gpio.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
void initPrimaryPins();
|
2021-11-16 01:15:29 -08:00
|
|
|
void initOutputPins();
|
2017-04-21 10:36:51 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_GPIO_HARDWARE
|
2017-04-21 10:36:51 -07:00
|
|
|
void turnAllPinsOff(void);
|
2017-04-21 12:14:37 -07:00
|
|
|
#else /* EFI_GPIO_HARDWARE */
|
2017-04-21 10:36:51 -07:00
|
|
|
#define turnAllPinsOff() {}
|
2017-04-21 12:14:37 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
|
|
|
|
2020-06-11 17:43:26 -07:00
|
|
|
|
2019-04-04 16:56:03 -07:00
|
|
|
#ifdef __cplusplus
|
2020-07-20 03:29:43 -07:00
|
|
|
|
2016-09-03 21:03:27 -07:00
|
|
|
|
2016-10-31 19:02:12 -07:00
|
|
|
class IgnitionOutputPin : public NamedOutputPin {
|
|
|
|
public:
|
|
|
|
IgnitionOutputPin();
|
2022-09-05 16:49:27 -07:00
|
|
|
void setHigh() override;
|
|
|
|
void setLow() override;
|
2016-10-31 19:02:12 -07:00
|
|
|
void reset();
|
2016-11-01 20:01:54 -07:00
|
|
|
int signalFallSparkId;
|
|
|
|
bool outOfOrder; // https://sourceforge.net/p/rusefi/tickets/319/
|
2022-09-05 16:49:27 -07:00
|
|
|
int8_t coilIndex;
|
2016-10-31 19:02:12 -07:00
|
|
|
};
|
|
|
|
|
2020-11-09 16:47:10 -08:00
|
|
|
/**
|
|
|
|
* OutputPin with semi-automated init/deinit on configuration change
|
|
|
|
*/
|
2020-11-09 18:10:48 -08:00
|
|
|
class RegisteredOutputPin : public virtual OutputPin {
|
2020-09-17 16:35:43 -07:00
|
|
|
public:
|
2022-10-23 05:25:47 -07:00
|
|
|
RegisteredOutputPin(const char *registrationName, size_t pinOffset, size_t pinModeOffset);
|
2021-11-16 01:15:29 -08:00
|
|
|
void init();
|
2020-09-17 16:35:43 -07:00
|
|
|
void unregister();
|
2022-10-23 05:25:47 -07:00
|
|
|
RegisteredOutputPin* const next;
|
2020-11-09 18:10:48 -08:00
|
|
|
const char *registrationName;
|
2020-11-19 20:57:06 -08:00
|
|
|
private:
|
2022-10-23 05:25:47 -07:00
|
|
|
const uint16_t m_pinOffset;
|
|
|
|
const uint16_t m_pinModeOffset;
|
2020-11-05 14:23:09 -08:00
|
|
|
bool isPinConfigurationChanged();
|
2020-09-17 16:35:43 -07:00
|
|
|
};
|
|
|
|
|
2020-11-09 18:10:48 -08:00
|
|
|
class RegisteredNamedOutputPin : public RegisteredOutputPin, public NamedOutputPin {
|
|
|
|
public:
|
2022-10-23 05:25:47 -07:00
|
|
|
RegisteredNamedOutputPin(const char *name, size_t pinOffset, size_t pinModeOffset);
|
2020-11-09 18:10:48 -08:00
|
|
|
};
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
class EnginePins {
|
2016-09-06 21:02:11 -07:00
|
|
|
public:
|
2016-11-03 20:02:58 -07:00
|
|
|
EnginePins();
|
2021-07-09 14:02:25 -07:00
|
|
|
void startPins();
|
2016-11-01 06:02:29 -07:00
|
|
|
void reset();
|
2020-11-19 20:57:06 -08:00
|
|
|
static void debug();
|
2016-11-03 20:02:58 -07:00
|
|
|
bool stopPins();
|
2021-07-09 14:02:25 -07:00
|
|
|
void unregisterPins();
|
2020-09-17 16:35:43 -07:00
|
|
|
RegisteredOutputPin mainRelay;
|
2020-11-03 10:19:56 -08:00
|
|
|
/**
|
|
|
|
* High Pressure Fuel Pump valve control
|
|
|
|
*/
|
2020-11-09 18:41:13 -08:00
|
|
|
RegisteredNamedOutputPin hpfpValve;
|
2020-03-24 22:28:37 -07:00
|
|
|
// this one cranks engine
|
2020-09-17 16:35:43 -07:00
|
|
|
RegisteredOutputPin starterControl;
|
2020-11-02 20:52:26 -08:00
|
|
|
// this one prevents driver from cranking engine
|
2020-09-17 16:35:43 -07:00
|
|
|
RegisteredOutputPin starterRelayDisable;
|
2020-03-24 22:28:37 -07:00
|
|
|
|
2020-09-17 16:35:43 -07:00
|
|
|
RegisteredOutputPin fanRelay;
|
2021-06-13 05:06:45 -07:00
|
|
|
RegisteredOutputPin fanRelay2;
|
|
|
|
|
2019-09-08 13:45:02 -07:00
|
|
|
// see acRelayPin
|
2020-09-27 04:22:09 -07:00
|
|
|
RegisteredOutputPin acRelay;
|
|
|
|
RegisteredOutputPin fuelPumpRelay;
|
2015-07-10 06:01:56 -07:00
|
|
|
OutputPin o2heater;
|
2022-08-24 10:20:14 -07:00
|
|
|
OutputPin luaOutputPins[LUA_PWM_COUNT];
|
|
|
|
|
2017-01-30 03:02:53 -08:00
|
|
|
/**
|
|
|
|
* brain board RED LED by default
|
|
|
|
*/
|
2017-02-24 16:42:34 -08:00
|
|
|
OutputPin errorLedPin;
|
2018-07-26 12:51:06 -07:00
|
|
|
OutputPin communicationLedPin; // blue LED on brain board by default
|
|
|
|
OutputPin warningLedPin; // orange LED on brain board by default
|
|
|
|
OutputPin runningLedPin; // green LED on brain board by default
|
2017-02-24 16:42:34 -08:00
|
|
|
|
2019-11-10 09:39:47 -08:00
|
|
|
OutputPin debugTriggerSync;
|
2020-09-27 04:22:09 -07:00
|
|
|
RegisteredOutputPin boostPin;
|
|
|
|
RegisteredOutputPin idleSolenoidPin;
|
|
|
|
RegisteredOutputPin secondIdleSolenoidPin;
|
|
|
|
RegisteredOutputPin alternatorPin;
|
2017-01-30 03:02:53 -08:00
|
|
|
/**
|
|
|
|
* this one is usually on the gauge cluster, not on the ECU
|
|
|
|
*/
|
2020-09-27 04:22:09 -07:00
|
|
|
RegisteredOutputPin checkEnginePin;
|
2017-11-26 19:30:37 -08:00
|
|
|
|
2020-11-09 18:10:48 -08:00
|
|
|
RegisteredNamedOutputPin tachOut;
|
2017-11-26 19:30:37 -08:00
|
|
|
|
2020-09-27 04:22:09 -07:00
|
|
|
RegisteredOutputPin triggerDecoderErrorPin;
|
2016-09-14 16:03:00 -07:00
|
|
|
OutputPin sdCsPin;
|
2017-08-27 21:08:37 -07:00
|
|
|
OutputPin accelerometerCs;
|
2016-09-13 21:03:14 -07:00
|
|
|
|
2021-07-06 17:14:08 -07:00
|
|
|
InjectorOutputPin injectors[MAX_CYLINDER_COUNT];
|
|
|
|
IgnitionOutputPin coils[MAX_CYLINDER_COUNT];
|
2021-07-09 05:37:46 -07:00
|
|
|
IgnitionOutputPin trailingCoils[MAX_CYLINDER_COUNT];
|
2017-11-26 19:30:37 -08:00
|
|
|
NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT];
|
2020-12-22 11:03:54 -08:00
|
|
|
OutputPin tcuSolenoids[TCU_SOLENOID_COUNT];
|
2022-04-12 16:15:09 -07:00
|
|
|
OutputPin tcuTccOnoffSolenoid;
|
|
|
|
OutputPin tcuTccPwmSolenoid;
|
2022-04-18 17:09:27 -07:00
|
|
|
OutputPin tcuPcSolenoid;
|
|
|
|
OutputPin tcu32Solenoid;
|
2020-12-22 11:03:54 -08:00
|
|
|
|
2020-11-02 21:46:03 -08:00
|
|
|
private:
|
2021-07-09 14:02:25 -07:00
|
|
|
void startInjectionPins();
|
|
|
|
void startIgnitionPins();
|
|
|
|
void startAuxValves();
|
2020-11-02 21:46:03 -08:00
|
|
|
|
2021-07-09 14:02:25 -07:00
|
|
|
void stopInjectionPins();
|
|
|
|
void stopIgnitionPins();
|
|
|
|
void stopAuxValves();
|
2016-09-06 21:02:11 -07:00
|
|
|
};
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-04 16:56:03 -07:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* it's a macro to be sure that stack is not used
|
|
|
|
* @return 0 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* it's a macro to be sure that stack is not used
|
|
|
|
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
|
|
|
|
|
|
|
|
#define getElectricalValue(logicalValue, mode) \
|
|
|
|
(logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_GPIO_HARDWARE
|
2017-04-21 14:38:13 -07:00
|
|
|
|
2019-04-04 16:56:03 -07:00
|
|
|
EXTERNC ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin);
|
|
|
|
EXTERNC ioportid_t getHwPort(const char *msg, brain_pin_e brainPin);
|
2017-04-21 13:20:06 -07:00
|
|
|
const char *portname(ioportid_t GPIOx);
|
2017-04-21 09:31:17 -07:00
|
|
|
|
2017-04-21 13:20:06 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
void printSpiConfig(const char *msg, spi_device_e device);
|
2017-04-21 13:20:06 -07:00
|
|
|
brain_pin_e parseBrainPin(const char *str);
|
2021-07-16 15:13:33 -07:00
|
|
|
|
|
|
|
extern EnginePins enginePins;
|