efiExtiEnablePin: return status to caller

This commit is contained in:
Andrey Gusakov 2024-03-05 23:30:08 +03:00 committed by rusefillc
parent a3ca49566e
commit f4cd6de86d
2 changed files with 17 additions and 12 deletions

View File

@ -35,24 +35,24 @@ struct ExtiChannel
static ExtiChannel channels[16];
// 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, ExtiCallback cb, void *cb_data) {
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data) {
/* paranoid check, in case of Gpio::Unassigned getHwPort will return NULL
* and we will fail on next check */
if (!isBrainPinValid(brainPin)) {
return;
return -1;
}
criticalAssertVoid(msg, "efiExtiEnablePin msg must not be null");
criticalAssert(msg, "efiExtiEnablePin msg must not be null", -1);
ioportid_t port = getHwPort(msg, brainPin);
if (port == NULL) {
return;
return -1;
}
bool wasUsed = brain_pin_markUsed(brainPin, msg);
if (wasUsed) {
// error condition we shall bail
return;
return -1;
}
int index = getHwPin(msg, brainPin);
@ -62,11 +62,11 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti
/* is this index already used? */
if (channel.Callback) {
firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %s/index %d: exti index already used by %s",
msg,
hwPortname(brainPin),
index,
channel.Name);
return;
msg,
hwPortname(brainPin),
index,
channel.Name);
return -1;
}
channel.Callback = cb;
@ -75,6 +75,8 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti
ioline_t line = PAL_LINE(port, index);
palEnableLineEvent(line, mode);
return 0;
}
void efiExtiDisablePin(brain_pin_e brainPin)
@ -256,7 +258,10 @@ void efiExtiInit() {
criticalError("exti not supported");
}
void efiExtiEnablePin(const char *, brain_pin_e, uint32_t, ExtiCallback, void *) { }
int efiExtiEnablePin(const char *, brain_pin_e, uint32_t, ExtiCallback, void *)
{
return 0;
}
void efiExtiDisablePin(brain_pin_e) { }
uint8_t getExtiOverflowCounter() {

View File

@ -12,7 +12,7 @@
using ExtiCallback = void(*)(void*, efitick_t);
void efiExtiInit();
void efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, ExtiCallback cb, void *cb_data);
int efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, ExtiCallback cb, void *cb_data);
void efiExtiDisablePin(brain_pin_e brainPin);
uint8_t getExtiOverflowCounter();
#endif /* HAL_USE_PAL */