EXTI refactoring
This commit is contained in:
parent
ee6e9b455d
commit
1c373573a2
|
@ -11,6 +11,7 @@
|
|||
#include "efiGpio.h"
|
||||
|
||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||
#include "pin_repository.h"
|
||||
#include "io_pins.h"
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
||||
|
||||
|
@ -454,6 +455,19 @@ const char *portname(ioportid_t GPIOx) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
|
||||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return EFI_ERROR_CODE;
|
||||
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return EFI_ERROR_CODE;
|
||||
}
|
||||
return brainPin % PORT_SIZE;
|
||||
}
|
||||
|
||||
#else /* EFI_GPIO_HARDWARE */
|
||||
const char *hwPortname(brain_pin_e brainPin) {
|
||||
(void)brainPin;
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* digital_input_exti.cpp
|
||||
*
|
||||
* Created on: Dec 18, 2018
|
||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
*/
|
||||
|
||||
#include "digital_input_exti.h"
|
||||
#include "efiGpio.h"
|
||||
|
||||
#if HAL_USE_EXT || defined(__DOXYGEN__)
|
||||
|
||||
/**
|
||||
* 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 EXTConfig extcfg = { {
|
||||
/* CH#00 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#01 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#02 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#03 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#04 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#05 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#06 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#07 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#08 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#09 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#10 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#11 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#12 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#13 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#14 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#15 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#16 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#17 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#18 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#19 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#20 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#21 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#22 */{ EXT_CH_MODE_DISABLED, NULL } } };
|
||||
|
||||
static uint32_t getExtMode(ioportid_t port) {
|
||||
if (port == GPIOA) {
|
||||
return EXT_MODE_GPIOA;
|
||||
} else if (port == GPIOB) {
|
||||
return EXT_MODE_GPIOB;
|
||||
} else if (port == GPIOC) {
|
||||
return EXT_MODE_GPIOC;
|
||||
} else if (port == GPIOD) {
|
||||
return EXT_MODE_GPIOD;
|
||||
} else if (port == GPIOE) {
|
||||
return EXT_MODE_GPIOE;
|
||||
} else if (port == GPIOF) {
|
||||
return EXT_MODE_GPIOF;
|
||||
}
|
||||
firmwareError(CUSTOM_ERR_EXT_MODE, "Unsupported %d", port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EXT is not able to give you the front direction but you could read the pin in the callback.
|
||||
void enableExti(brain_pin_e pin, uint32_t mode, extcallback_t cb) {
|
||||
if (pin == GPIO_UNASSIGNED)
|
||||
return;
|
||||
|
||||
int index = getHwPin("joy", pin);
|
||||
ioportid_t port = getHwPort("joy", pin);
|
||||
|
||||
extcfg.channels[index].mode = mode | EXT_CH_MODE_AUTOSTART | getExtMode(port);
|
||||
extcfg.channels[index].cb = cb;
|
||||
}
|
||||
|
||||
void myExtStart(void) {
|
||||
extStart(&EXTD1, &extcfg);
|
||||
}
|
||||
|
||||
#endif /* HAL_USE_EXT */
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* digital_input_exti.h
|
||||
*
|
||||
* Created on: Dec 18, 2018
|
||||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
*/
|
||||
|
||||
#ifndef HW_LAYER_DIGITAL_INPUT_EXTI_H_
|
||||
#define HW_LAYER_DIGITAL_INPUT_EXTI_H_
|
||||
|
||||
#include "global.h"
|
||||
|
||||
void enableExti(brain_pin_e pin, uint32_t mode, extcallback_t cb);
|
||||
void myExtStart(void);
|
||||
|
||||
#endif /* HW_LAYER_DIGITAL_INPUT_EXTI_H_ */
|
|
@ -13,6 +13,7 @@ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
|||
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input_hw.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input_exti.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/mmc_card.cpp \
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
*/
|
||||
|
||||
#include <board.h>
|
||||
//#include "board.h"
|
||||
#include "global.h"
|
||||
#include "io_pins.h"
|
||||
#include "efiGpio.h"
|
||||
|
@ -43,19 +43,6 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
|||
return PORTS[brainPin / PORT_SIZE];
|
||||
}
|
||||
|
||||
/**
|
||||
* this method returns the numeric part of pin name. For instance, for PC13 this would return '13'
|
||||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return EFI_ERROR_CODE;
|
||||
if (brainPin > GPIO_UNASSIGNED || brainPin < 0) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return EFI_ERROR_CODE;
|
||||
}
|
||||
return brainPin % PORT_SIZE;
|
||||
}
|
||||
|
||||
bool efiReadPin(brain_pin_e pin) {
|
||||
return palReadPad(getHwPort("readPin", pin), getHwPin("readPin", pin));
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2018
|
||||
*/
|
||||
|
||||
#include "engine_configuration.h"
|
||||
#include "joystick.h"
|
||||
#include "engine.h"
|
||||
#include "joystick.h"
|
||||
#include "pin_repository.h"
|
||||
#include "digital_input_exti.h"
|
||||
|
||||
#if HAL_USE_EXT || defined(__DOXYGEN__)
|
||||
|
||||
|
@ -91,69 +91,6 @@ static void joystickInfo(void) {
|
|||
scheduleMsg(sharedLogger, "d=%d@%s", joyD, hwPortname(boardConfiguration->joystickDPin));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 EXTConfig extcfg = { {
|
||||
/* CH#00 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#01 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#02 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#03 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#04 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#05 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#06 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#07 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#08 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#09 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#10 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#11 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#12 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#13 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#14 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#15 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#16 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#17 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#18 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#19 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#20 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#21 */{ EXT_CH_MODE_DISABLED, NULL },
|
||||
/* CH#22 */{ EXT_CH_MODE_DISABLED, NULL } } };
|
||||
|
||||
static uint32_t getExtMode(ioportid_t port) {
|
||||
if (port == GPIOA) {
|
||||
return EXT_MODE_GPIOA;
|
||||
} else if (port == GPIOB) {
|
||||
return EXT_MODE_GPIOB;
|
||||
} else if (port == GPIOC) {
|
||||
return EXT_MODE_GPIOC;
|
||||
} else if (port == GPIOD) {
|
||||
return EXT_MODE_GPIOD;
|
||||
} else if (port == GPIOE) {
|
||||
return EXT_MODE_GPIOE;
|
||||
} else if (port == GPIOF) {
|
||||
return EXT_MODE_GPIOF;
|
||||
}
|
||||
firmwareError(CUSTOM_ERR_EXT_MODE, "Unsupported %d", port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EXT is not able to give you the front direction but you could read the pin in the callback.
|
||||
static void enableExti(brain_pin_e pin, extcallback_t cb) {
|
||||
if (pin == GPIO_UNASSIGNED)
|
||||
return;
|
||||
|
||||
int index = getHwPin("joy", pin);
|
||||
ioportid_t port = getHwPort("joy", pin);
|
||||
|
||||
extcfg.channels[index].mode = EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | getExtMode(port);
|
||||
extcfg.channels[index].cb = cb;
|
||||
}
|
||||
|
||||
static bool isJoystickEnabled() {
|
||||
return boardConfiguration->joystickCenterPin != GPIO_UNASSIGNED ||
|
||||
boardConfiguration->joystickAPin != GPIO_UNASSIGNED ||
|
||||
|
@ -167,11 +104,11 @@ void initJoystick(Logging *shared) {
|
|||
return;
|
||||
sharedLogger = shared;
|
||||
|
||||
enableExti(boardConfiguration->joystickCenterPin, extCallback);
|
||||
enableExti(boardConfiguration->joystickAPin, extCallback);
|
||||
enableExti(boardConfiguration->joystickCenterPin, EXT_CH_MODE_RISING_EDGE, extCallback);
|
||||
enableExti(boardConfiguration->joystickAPin, EXT_CH_MODE_RISING_EDGE, extCallback);
|
||||
// not used so far applyPin(boardConfiguration->joystickBPin);
|
||||
// not used so far applyPin(boardConfiguration->joystickCPin);
|
||||
enableExti(boardConfiguration->joystickDPin, extCallback);
|
||||
enableExti(boardConfiguration->joystickDPin, EXT_CH_MODE_RISING_EDGE, extCallback);
|
||||
|
||||
efiSetPadMode("joy center", boardConfiguration->joystickCenterPin, PAL_MODE_INPUT_PULLUP);
|
||||
efiSetPadMode("joy A", boardConfiguration->joystickAPin, PAL_MODE_INPUT_PULLUP);
|
||||
|
@ -181,7 +118,8 @@ void initJoystick(Logging *shared) {
|
|||
|
||||
addConsoleAction("joystickinfo", joystickInfo);
|
||||
|
||||
extStart(&EXTD1, &extcfg);
|
||||
// todo: this is not a great place to invoke this method. open question if we have to start only after enablng all EXTI?
|
||||
myExtStart();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* HAL_USE_EXT */
|
||||
|
|
Loading…
Reference in New Issue