From 0c095ddd156bda5c16ba4573c5978ff77ba1879b Mon Sep 17 00:00:00 2001 From: dron0gus Date: Sun, 17 May 2020 02:15:49 +0300 Subject: [PATCH] Minor fixes (#1442) * exti trigger: mark pins used, handle errors * MC33810 add to smart gpios --- firmware/config/boards/kinetis/efifeatures.h | 1 + firmware/config/boards/prometheus/efifeatures.h | 3 +++ firmware/config/boards/skeleton/efifeatures.h | 1 + firmware/config/stm32f4ems/efifeatures.h | 4 ++++ firmware/config/stm32f7ems/efifeatures.h | 4 ++++ firmware/hw_layer/digital_input_exti.cpp | 13 +++++++++---- firmware/hw_layer/digital_input_exti.h | 2 +- firmware/hw_layer/digital_input_icu.cpp | 1 - firmware/hw_layer/smart_gpio.h | 12 ++++++++++-- firmware/hw_layer/trigger_input_exti.cpp | 7 +++++-- 10 files changed, 38 insertions(+), 10 deletions(-) diff --git a/firmware/config/boards/kinetis/efifeatures.h b/firmware/config/boards/kinetis/efifeatures.h index 6ce4aad1bf..123c18b2ed 100644 --- a/firmware/config/boards/kinetis/efifeatures.h +++ b/firmware/config/boards/kinetis/efifeatures.h @@ -339,6 +339,7 @@ #define BOARD_TLE6240_COUNT 1 #define BOARD_MC33972_COUNT 0 #define BOARD_TLE8888_COUNT 0 +#define BOARD_MC33810_COUNT 0 #define TLE6240_SS_PORT GPIOB #define TLE6240_SS_PAD 0U diff --git a/firmware/config/boards/prometheus/efifeatures.h b/firmware/config/boards/prometheus/efifeatures.h index 6d824aca2a..cebcf58a6f 100644 --- a/firmware/config/boards/prometheus/efifeatures.h +++ b/firmware/config/boards/prometheus/efifeatures.h @@ -70,6 +70,9 @@ #define BOARD_TLE8888_COUNT 0 #endif +#ifndef BOARD_MC33810_COUNT +#define BOARD_MC33810_COUNT 0 +#endif #undef EFI_CONSOLE_TX_BRAIN_PIN #define EFI_CONSOLE_TX_BRAIN_PIN GPIOA_0 diff --git a/firmware/config/boards/skeleton/efifeatures.h b/firmware/config/boards/skeleton/efifeatures.h index bfbe2c52a2..d165f1e0cf 100644 --- a/firmware/config/boards/skeleton/efifeatures.h +++ b/firmware/config/boards/skeleton/efifeatures.h @@ -85,6 +85,7 @@ #define BOARD_TLE6240_COUNT 0 #define BOARD_MC33972_COUNT 0 #define BOARD_TLE8888_COUNT 0 +#define BOARD_MC33810_COUNT 0 /** * if you have a 60-2 trigger, or if you just want better performance, you diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index efdfb23e59..8399ae4450 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -146,6 +146,10 @@ #define BOARD_TLE8888_COUNT 1 #endif +#ifndef BOARD_MC33810_COUNT +#define BOARD_MC33810_COUNT 0 +#endif + #define EFI_ANALOG_SENSORS TRUE #ifndef EFI_MAX_31855 diff --git a/firmware/config/stm32f7ems/efifeatures.h b/firmware/config/stm32f7ems/efifeatures.h index bffe61773f..96a08b579b 100644 --- a/firmware/config/stm32f7ems/efifeatures.h +++ b/firmware/config/stm32f7ems/efifeatures.h @@ -50,6 +50,10 @@ #define BOARD_TLE8888_COUNT 1 #endif +#ifndef BOARD_MC33810_COUNT +#define BOARD_MC33810_COUNT 0 +#endif + #undef EFI_CAN_SUPPORT #define EFI_CAN_SUPPORT TRUE diff --git a/firmware/hw_layer/digital_input_exti.cpp b/firmware/hw_layer/digital_input_exti.cpp index dfa9d71da7..b746af04f0 100644 --- a/firmware/hw_layer/digital_input_exti.cpp +++ b/firmware/hw_layer/digital_input_exti.cpp @@ -11,6 +11,7 @@ #include "digital_input_exti.h" #include "efi_gpio.h" #include "error_handling.h" +#include "pin_repository.h" /** * EXTI is a funny thing: you can only use same pin on one port. For example, you can use @@ -23,23 +24,23 @@ static ioportmask_t ext_used = 0; // EXT is not able to give you the front direction but you could read the pin in the callback. -void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palcallback_t cb, void *cb_data) { +int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palcallback_t cb, void *cb_data) { /* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL * and we will fail on next check */ if (brainPin == GPIO_UNASSIGNED) - return; + return -1; ioportid_t port = getHwPort(msg, brainPin); if (port == NULL) - return; + return -1; int index = getHwPin(msg, brainPin); /* is this index already used? */ if (ext_used & PAL_PORT_BIT(index)) { firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %d: exti index already used", msg, brainPin); - return; + return -1; } ioline_t line = PAL_LINE(port, index); @@ -48,6 +49,9 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palc /* mark used */ ext_used |= PAL_PORT_BIT(index); + brain_pin_markUsed(brainPin, msg); + + return 0; } void efiExtiDisablePin(brain_pin_e brainPin) @@ -73,6 +77,7 @@ void efiExtiDisablePin(brain_pin_e brainPin) /* mark unused */ ext_used &= ~PAL_PORT_BIT(index); + brain_pin_markUnused(brainPin); } #endif /* HAL_USE_PAL && EFI_PROD_CODE */ diff --git a/firmware/hw_layer/digital_input_exti.h b/firmware/hw_layer/digital_input_exti.h index 6d4ab49f07..cc4112928c 100644 --- a/firmware/hw_layer/digital_input_exti.h +++ b/firmware/hw_layer/digital_input_exti.h @@ -10,6 +10,6 @@ #include "digital_input.h" #if HAL_USE_PAL -void efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data); +int efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data); void efiExtiDisablePin(brain_pin_e brainPin); #endif /* HAL_USE_PAL */ diff --git a/firmware/hw_layer/digital_input_icu.cpp b/firmware/hw_layer/digital_input_icu.cpp index f21370088f..73fb062534 100644 --- a/firmware/hw_layer/digital_input_icu.cpp +++ b/firmware/hw_layer/digital_input_icu.cpp @@ -221,7 +221,6 @@ void stopDigitalCapture(const char *msg, brain_pin_e brainPin) { if (brainPin == GPIO_UNASSIGNED) { return; } - brain_pin_markUnused(brainPin); ICUDriver *driver = getInputCaptureDriver(msg, brainPin); if (driver == NULL) { diff --git a/firmware/hw_layer/smart_gpio.h b/firmware/hw_layer/smart_gpio.h index bb481a90c9..1f5c4ff96d 100644 --- a/firmware/hw_layer/smart_gpio.h +++ b/firmware/hw_layer/smart_gpio.h @@ -12,7 +12,11 @@ #include "drivers/gpio/tle6240.h" #include "drivers/gpio/mc33972.h" #include "drivers/gpio/tle8888.h" - #define BOARD_EXT_PINREPOPINS (BOARD_TLE6240_COUNT * TLE6240_OUTPUTS + BOARD_MC33972_COUNT * MC33972_INPUTS + BOARD_TLE8888_COUNT * TLE8888_OUTPUTS) + #define BOARD_EXT_PINREPOPINS \ + (BOARD_TLE6240_COUNT * TLE6240_OUTPUTS + \ + BOARD_MC33972_COUNT * MC33972_INPUTS + \ + BOARD_TLE8888_COUNT * TLE8888_OUTPUTS + \ + BOARD_MC33810_COUNT * MC33810_OUTPUTS) #else /* EFI_PROD_CODE */ #define BOARD_EXT_PINREPOPINS 0 @@ -21,7 +25,11 @@ #if EFI_UNIT_TEST #define BOARD_EXT_GPIOCHIPS 3 #else - #define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT) + #define BOARD_EXT_GPIOCHIPS \ + (BOARD_TLE6240_COUNT + \ + BOARD_MC33972_COUNT + \ + BOARD_TLE8888_COUNT + \ + BOARD_MC33810_COUNT) #endif void initSmartGpio(void); diff --git a/firmware/hw_layer/trigger_input_exti.cpp b/firmware/hw_layer/trigger_input_exti.cpp index 981446029f..c36b6bc5c1 100644 --- a/firmware/hw_layer/trigger_input_exti.cpp +++ b/firmware/hw_layer/trigger_input_exti.cpp @@ -76,6 +76,7 @@ static void cam_callback(void *arg) { /*==========================================================================*/ int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) { + int ret; brain_pin_e brainPin = isTriggerShaft ? CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index]; scheduleMsg(logger, "extiTriggerTurnOnInputPin %s %s", msg, hwPortname(brainPin)); @@ -83,8 +84,10 @@ int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) { /* TODO: * * do not set to both edges if we need only one * * simplify callback in case of one edge */ - ioline_t pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin)); - efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line); + ioline_t pal_line = PAL_LINE(getHwPort(msg, brainPin), getHwPin(msg, brainPin)); + ret = efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line); + if (ret) + return ret; return 0; }