rusefi-1/firmware/hw_layer/digital_input_exti.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

2018-12-18 20:50:29 -08:00
/*
* digital_input_exti.cpp
*
* Created on: Dec 18, 2018
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2018-12-18 20:50:29 -08:00
*/
2019-01-03 21:16:08 -08:00
#include "global.h"
2018-12-18 20:50:29 -08:00
2019-04-12 17:52:51 -07:00
#if HAL_USE_PAL && EFI_PROD_CODE
2019-01-03 21:16:08 -08:00
#include "digital_input_exti.h"
2019-03-29 06:11:13 -07:00
#include "efi_gpio.h"
#include "error_handling.h"
2018-12-18 20:50:29 -08:00
/**
* EXTI is a funny thing: you can only use same pin on one port. For example, you can use
* PA0 PB5 PE2 PD7
* but you cannot use
* PA0 PB0 PE2 PD7
* because pin '0' would be used on two different ports
*/
static ioportmask_t ext_used = 0;
2018-12-18 20:50:29 -08:00
// 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) {
2019-04-21 07:00:14 -07:00
/* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL
* and we will fail on next check */
if (brainPin == GPIO_UNASSIGNED)
return;
2019-04-21 07:00:14 -07:00
ioportid_t port = getHwPort(msg, brainPin);
if (port == NULL)
return;
2019-04-21 07:00:14 -07:00
int index = getHwPin(msg, brainPin);
2018-12-18 20:50:29 -08:00
/* 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;
}
2018-12-18 20:50:29 -08:00
2019-04-21 07:00:14 -07:00
ioline_t line = PAL_LINE(port, index);
palEnableLineEvent(line, mode);
palSetLineCallback(line, cb, cb_data);
/* mark used */
ext_used |= PAL_PORT_BIT(index);
}
void efiExtiDisablePin(brain_pin_e brainPin)
{
2019-04-21 07:00:14 -07:00
/* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL
* and we will fail on next check */
if (brainPin == GPIO_UNASSIGNED)
return;
2019-04-21 07:00:14 -07:00
ioportid_t port = getHwPort("exti", brainPin);
if (port == NULL)
return;
2019-04-21 07:00:14 -07:00
int index = getHwPin("exti", brainPin);
/* is this index was used? */
if (!(ext_used & PAL_PORT_BIT(index))) {
return;
}
2019-04-21 07:00:14 -07:00
ioline_t line = PAL_LINE(port, index);
palDisableLineEvent(line);
/* mark unused */
ext_used &= ~PAL_PORT_BIT(index);
2018-12-18 20:50:29 -08:00
}
#endif /* HAL_USE_PAL && EFI_PROD_CODE */