trigger signal debug pins - logic level output #2959

This commit is contained in:
Andrey 2021-07-15 01:28:44 -04:00
parent 26481f4c2a
commit 23be588af6
11 changed files with 99 additions and 79 deletions

View File

@ -92,9 +92,10 @@
#include "hip9011.h"
#endif
#include "hardware.h"
#if EFI_PROD_CODE
#include "init.h"
#include "hardware.h"
#include "board.h"
#endif /* EFI_PROD_CODE */
@ -173,11 +174,13 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_DEFAILED_LOGGING
efiPrintf("set globalConfigurationVersion=%d", globalConfigurationVersion);
#endif /* EFI_DEFAILED_LOGGING */
applyNewHardwareSettings(PASS_ENGINE_PARAMETER_SIGNATURE);
/**
* All these callbacks could be implemented as listeners, but these days I am saving RAM
*/
#if EFI_PROD_CODE
applyNewHardwareSettings(PASS_ENGINE_PARAMETER_SIGNATURE);
reconfigureSensors();
#endif /* EFI_PROD_CODE */
engine->preCalculate(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -188,12 +188,12 @@ void stopTriggerDebugPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void startTriggerDebugPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
for (int i = 0; i < TRIGGER_INPUT_PIN_COUNT; i++) {
if (isConfigurationChanged(triggerInputDebugPins[i])) {
efiSetPadMode("trigger debug", CONFIG(triggerInputDebugPins[i]), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("trigger debug", CONFIG(triggerInputDebugPins[i]), PAL_MODE_OUTPUT_PUSHPULL PASS_CONFIG_PARAMETER_SUFFIX);
}
}
for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
if (isConfigurationChanged(camInputsDebug[i])) {
efiSetPadMode("cam debug", CONFIG(camInputsDebug[i]), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("cam debug", CONFIG(camInputsDebug[i]), PAL_MODE_OUTPUT_PUSHPULL PASS_CONFIG_PARAMETER_SUFFIX);
}
}
}

View File

@ -33,6 +33,9 @@ void applyNewTriggerInputPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void startTriggerInputPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void stopTriggerInputPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void stopTriggerDebugPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void startTriggerDebugPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if HAL_TRIGGER_USE_ADC && HAL_USE_ADC
// This detector has 2 modes for low-RPM (ADC) and fast-RPM (EXTI)
enum triggerAdcMode_t {

View File

@ -375,6 +375,8 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiSetPadUnused(activeConfiguration.clutchUpPin);
}
stopTriggerDebugPins(PASS_ENGINE_PARAMETER_SIGNATURE);
enginePins.unregisterPins();
ButtonDebounce::startConfigurationList();
@ -387,9 +389,7 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
startTriggerInputPins(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_SHAFT_POSITION_INPUT */
#if (HAL_USE_PAL && EFI_JOYSTICK)
startJoystickPins();
#endif /* HAL_USE_PAL && EFI_JOYSTICK */
startHardware(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_HD44780_LCD
startHD44780_pins();
@ -508,6 +508,17 @@ void initHardwareNoConfig(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#endif // EFI_FILE_LOGGING
}
/**
* This method is invoked both on ECU start and configuration change
*/
void startHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if (HAL_USE_PAL && EFI_JOYSTICK)
startJoystickPins();
#endif /* HAL_USE_PAL && EFI_JOYSTICK */
startTriggerDebugPins(PASS_ENGINE_PARAMETER_SIGNATURE);
}
void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_HD44780_LCD
lcd_HD44780_init();
@ -608,6 +619,8 @@ void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
calcFastAdcIndexes();
startHardware(PASS_ENGINE_PARAMETER_SIGNATURE);
efiPrintf("initHardware() OK!");
}

View File

@ -9,6 +9,8 @@
#include "global.h"
void startHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if HAL_USE_SPI
// Peripherial Clock 42MHz SPI2 SPI3

View File

@ -49,7 +49,43 @@ void efiSetPadUnused(brain_pin_e brainPin) {
brain_pin_markUnused(brainPin);
}
/**
* This method would set an error condition if pin is already used
*/
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode DECLARE_CONFIG_PARAMETER_SUFFIX) {
if (!isBrainPinValid(brainPin)) {
// No pin configured, nothing to do here.
return;
}
bool wasUsed = brain_pin_markUsed(brainPin, msg PASS_CONFIG_PARAMETER_SUFFIX);
if (!wasUsed) {
efiSetPadModeWithoutOwnershipAcquisition(msg, brainPin, mode);
}
}
void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brainPin, iomode_t mode) {
#if EFI_PROD_CODE
/*check if on-chip pin or external */
if (brain_pin_is_onchip(brainPin)) {
/* on-chip */
ioportid_t port = getHwPort(msg, brainPin);
ioportmask_t pin = getHwPin(msg, brainPin);
/* paranoid */
if (port == GPIO_NULL)
return;
palSetPadMode(port, pin, mode);
}
#if (BOARD_EXT_GPIOCHIPS > 0)
else {
gpiochips_setPadMode(brainPin, mode);
}
#endif
#endif /* EFI_PROD_CODE */
}
#if EFI_PROD_CODE
@ -71,44 +107,6 @@ bool efiReadPin(brain_pin_e pin) {
return false;
}
void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brainPin, iomode_t mode)
{
/*check if on-chip pin or external */
if (brain_pin_is_onchip(brainPin)) {
/* on-chip */
ioportid_t port = getHwPort(msg, brainPin);
ioportmask_t pin = getHwPin(msg, brainPin);
/* paranoid */
if (port == GPIO_NULL)
return;
palSetPadMode(port, pin, mode);
}
#if (BOARD_EXT_GPIOCHIPS > 0)
else {
gpiochips_setPadMode(brainPin, mode);
}
#endif
}
/**
* This method would set an error condition if pin is already used
*/
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
{
if (!isBrainPinValid(brainPin)) {
// No pin configured, nothing to do here.
return;
}
bool wasUsed = brain_pin_markUsed(brainPin, msg);
if (!wasUsed) {
efiSetPadModeWithoutOwnershipAcquisition(msg, brainPin, mode);
}
}
iomode_t getInputMode(pin_input_mode_e mode) {
switch (mode) {
case PI_PULLUP:

View File

@ -9,6 +9,7 @@
#pragma once
#include "global.h"
#include "engine_ptr.h"
#define INITIAL_PIN_STATE -1
#define GPIO_NULL NULL
@ -19,7 +20,7 @@
}
EXTERNC void efiSetPadMode(const char *msg, brain_pin_e pin, iomode_t mode);
EXTERNC void efiSetPadMode(const char *msg, brain_pin_e pin, iomode_t mode DECLARE_CONFIG_PARAMETER_SUFFIX);
EXTERNC void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brainPin, iomode_t mode);
EXTERNC void efiSetPadUnused(brain_pin_e brainPin);

View File

@ -11,6 +11,8 @@
#include "pin_repository.h"
EXTERN_CONFIG;
static PinRepository pinRepository;
// todo: move this into PinRepository class
@ -58,6 +60,35 @@ static int brainPin_to_index(brain_pin_e brainPin)
return i;
}
/**
* See also brain_pin_markUnused()
* @return true if this pin was already used, false otherwise
*/
bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg DECLARE_CONFIG_PARAMETER_SUFFIX) {
#if ! EFI_BOOTLOADER
efiPrintf("%s on %s", msg, hwPortname(brainPin));
#endif
int index = brainPin_to_index(brainPin);
if (index < 0)
return true;
if (getBrainUsedPin(index) != NULL) {
/* TODO: get readable name of brainPin... */
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "Pin \"%s\" required by \"%s\" but is used by \"%s\" %s",
hwPortname(brainPin),
msg,
getBrainUsedPin(index),
getEngine_type_e(engineConfiguration->engineType));
return true;
}
getBrainUsedPin(index) = msg;
pinRepository.totalPinsUsed++;
return false;
}
/**
* See also brain_pin_markUsed()
*/
@ -237,35 +268,6 @@ bool brain_pin_is_ext(brain_pin_e brainPin)
return false;
}
/**
* See also brain_pin_markUnused()
* @return true if this pin was already used, false otherwise
*/
bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg) {
#if ! EFI_BOOTLOADER
efiPrintf("%s on %s", msg, hwPortname(brainPin));
#endif
int index = brainPin_to_index(brainPin);
if (index < 0)
return true;
if (getBrainUsedPin(index) != NULL) {
/* TODO: get readable name of brainPin... */
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "Pin \"%s\" required by \"%s\" but is used by \"%s\" %s",
hwPortname(brainPin),
msg,
getBrainUsedPin(index),
getEngine_type_e(engineConfiguration->engineType));
return true;
}
getBrainUsedPin(index) = msg;
pinRepository.totalPinsUsed++;
return false;
}
/**
* Marks on-chip gpio port-pin as used. Works only for on-chip gpios
* To be replaced with brain_pin_markUsed later

View File

@ -36,7 +36,7 @@ EXTERNC bool brain_pin_is_ext(brain_pin_e brainPin);
/**
* Usually high-level code would invoke efiSetPadMode, not this method directly
*/
EXTERNC bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg);
EXTERNC bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg DECLARE_CONFIG_PARAMETER_SUFFIX);
/**
* See also efiSetPadUnused
*/

View File

@ -124,8 +124,6 @@ void initJoystick() {
// not used so far applyPin(CONFIG(joystickCPin));
channel = getHwPin("joy", CONFIG(joystickDPin));
efiExtiEnablePin("joy", CONFIG(joystickDPin), PAL_EVENT_MODE_RISING_EDGE, (palcallback_t)(void *)extCallback, (void *)channel);
startJoystickPins();
}
#endif /* HAL_USE_PAL && EFI_JOYSTICK */

View File

@ -12,9 +12,9 @@
#include <ch.h>
#include <hal.h>
#include "chprintf.h"
#include "io_pins.h"
#ifdef __cplusplus
#include "io_pins.h"
// ChibiOS c++ wrappers
#include "ch.hpp"
#endif /* __cplusplus */