Debounce pin management (#1760)
* add linked list * macros, and use in buttonshift * unit_tests macros * add extern * add parens * move extern * move extern * move buttonDebounceListHead * move buttonDebouncePointerHead * merge gore * undo * reduce unused size * don't store pointer if already initialized * few changes * remove oldPin * fix merge conflict * merge in changes commited to wrong branch * fix definition * out of class? * brute force programming * fix few problemos * am confuse * am confuse * am confuse * am confuse * oldPin snuck in * move to public? * define again * try constexpr * def in cpp * remove constexpr * fix def * fix? * update active * fix a few things
This commit is contained in:
parent
8f8d4eccaf
commit
cab4cd0df2
|
@ -14,8 +14,8 @@ ButtonShiftController buttonShiftController;
|
||||||
|
|
||||||
void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void ButtonShiftController::init (DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
// 500 millisecond is maybe a little long?
|
// 500 millisecond is maybe a little long?
|
||||||
debounceUp.init(500, CONFIG(tcuUpshiftButtonPin), CONFIG(tcuUpshiftButtonPinMode));
|
debounceUp.init(500, &CONFIG(tcuUpshiftButtonPin), &CONFIG(tcuUpshiftButtonPinMode));
|
||||||
debounceDown.init(500, CONFIG(tcuDownshiftButtonPin), CONFIG(tcuDownshiftButtonPinMode));
|
debounceDown.init(500, &CONFIG(tcuDownshiftButtonPin), &CONFIG(tcuDownshiftButtonPinMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonShiftController::update() {
|
void ButtonShiftController::update() {
|
||||||
|
|
|
@ -6,16 +6,60 @@
|
||||||
* @author David Holdeman, (c) 2020
|
* @author David Holdeman, (c) 2020
|
||||||
*/
|
*/
|
||||||
#include "debounce.h"
|
#include "debounce.h"
|
||||||
|
#include "pin_repository.h"
|
||||||
|
#include "engine_configuration.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
|
||||||
void ButtonDebounce::init (int t, brain_pin_e p, pin_input_mode_e m) {
|
ButtonDebounce* ButtonDebounce::s_firstDebounce = nullptr;
|
||||||
|
|
||||||
|
void ButtonDebounce::init (int t, brain_pin_e *pin, pin_input_mode_e *mode) {
|
||||||
|
if (!initialized) {
|
||||||
|
ButtonDebounce *listItem = s_firstDebounce;
|
||||||
|
if (listItem == nullptr) {
|
||||||
|
s_firstDebounce = this;
|
||||||
|
} else {
|
||||||
|
while (listItem->nextDebounce != nullptr) {
|
||||||
|
listItem = listItem->nextDebounce;
|
||||||
|
}
|
||||||
|
listItem->nextDebounce = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
threshold = MS2NT(t);
|
threshold = MS2NT(t);
|
||||||
timeLast = 0;
|
timeLast = 0;
|
||||||
pin = p;
|
this->pin = pin;
|
||||||
|
active_pin = *pin;
|
||||||
|
this->mode = mode;
|
||||||
|
active_mode = *mode;
|
||||||
#ifdef PAL_MODE_INPUT_PULLDOWN
|
#ifdef PAL_MODE_INPUT_PULLDOWN
|
||||||
// getInputMode converts from pin_input_mode_e to iomode_t
|
// getInputMode converts from pin_input_mode_e to iomode_t
|
||||||
mode = getInputMode(m);
|
efiSetPadMode("Button", active_pin, getInputMode(active_mode));
|
||||||
efiSetPadMode("Button", p, mode);
|
|
||||||
#endif
|
#endif
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonDebounce::updateConfigurationList () {
|
||||||
|
ButtonDebounce *listItem = s_firstDebounce;
|
||||||
|
while (listItem != nullptr) {
|
||||||
|
listItem->updateConfiguration();
|
||||||
|
if (listItem->nextDebounce != nullptr) {
|
||||||
|
listItem = listItem->nextDebounce;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonDebounce::updateConfiguration () {
|
||||||
|
#ifndef EFI_ACTIVE_CONFIGURATION_IN_FLASH
|
||||||
|
if (*pin != active_pin || *mode != active_mode) {
|
||||||
|
#else
|
||||||
|
if (*pin != active_pin || *mode != active_mode || (isActiveConfigurationVoid && (*pin != 0 || *mode != 0))) {
|
||||||
|
#endif /* EFI_ACTIVE_CONFIGURATION_IN_FLASH */
|
||||||
|
brain_pin_markUnused(active_pin);
|
||||||
|
efiSetPadMode("Button", *pin, getInputMode(*mode));
|
||||||
|
}
|
||||||
|
active_pin = *pin;
|
||||||
|
active_mode = *mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,9 +80,9 @@ bool ButtonDebounce::readPinEvent() {
|
||||||
// for example to implement long button presses, it will be needed.
|
// for example to implement long button presses, it will be needed.
|
||||||
readValue = false;
|
readValue = false;
|
||||||
#ifdef PAL_MODE_INPUT_PULLDOWN
|
#ifdef PAL_MODE_INPUT_PULLDOWN
|
||||||
readValue = efiReadPin(pin);
|
readValue = efiReadPin(active_pin);
|
||||||
// Invert
|
// Invert
|
||||||
if (mode != PAL_MODE_INPUT_PULLDOWN) {
|
if (getInputMode(active_mode) == PAL_MODE_INPUT_PULLUP) {
|
||||||
readValue = !readValue;
|
readValue = !readValue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,17 +5,29 @@
|
||||||
* @date Aug 31, 2020
|
* @date Aug 31, 2020
|
||||||
* @author David Holdeman, (c) 2020
|
* @author David Holdeman, (c) 2020
|
||||||
*/
|
*/
|
||||||
|
#ifndef DEBOUNCE_INC
|
||||||
|
#define DEBOUNCE_INC
|
||||||
|
|
||||||
#include "globalaccess.h"
|
#include "globalaccess.h"
|
||||||
#include "io_pins.h"
|
#include "io_pins.h"
|
||||||
|
|
||||||
class ButtonDebounce {
|
class ButtonDebounce {
|
||||||
public:
|
public:
|
||||||
void init(int t, brain_pin_e p, pin_input_mode_e m);
|
void init(int t, brain_pin_e *p, pin_input_mode_e *m);
|
||||||
|
void updateConfiguration();
|
||||||
bool readPinEvent();
|
bool readPinEvent();
|
||||||
|
static void updateConfigurationList();
|
||||||
private:
|
private:
|
||||||
int threshold;
|
int threshold;
|
||||||
efitick_t timeLast;
|
efitick_t timeLast;
|
||||||
brain_pin_e pin;
|
brain_pin_e *pin;
|
||||||
iomode_t mode;
|
brain_pin_e active_pin;
|
||||||
|
pin_input_mode_e *mode;
|
||||||
|
pin_input_mode_e active_mode;
|
||||||
bool readValue;
|
bool readValue;
|
||||||
|
bool initialized = false;
|
||||||
|
ButtonDebounce *nextDebounce = nullptr;
|
||||||
|
static ButtonDebounce* s_firstDebounce;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* DEBOUNCE_INC */
|
||||||
|
|
|
@ -264,9 +264,12 @@ void stopSpi(spi_device_e device) {
|
||||||
* this method is NOT currently invoked on ECU start
|
* this method is NOT currently invoked on ECU start
|
||||||
* todo: maybe start invoking this method on ECU start so that peripheral start-up initialization and restart are unified?
|
* todo: maybe start invoking this method on ECU start so that peripheral start-up initialization and restart are unified?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void applyNewHardwareSettings(void) {
|
void applyNewHardwareSettings(void) {
|
||||||
// all 'stop' methods need to go before we begin starting pins
|
// all 'stop' methods need to go before we begin starting pins
|
||||||
|
|
||||||
|
ButtonDebounce::updateConfigurationList();
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT
|
#if EFI_SHAFT_POSITION_INPUT
|
||||||
stopTriggerInputPins();
|
stopTriggerInputPins();
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
@ -275,7 +278,7 @@ void applyNewHardwareSettings(void) {
|
||||||
#if (HAL_USE_PAL && EFI_JOYSTICK)
|
#if (HAL_USE_PAL && EFI_JOYSTICK)
|
||||||
stopJoystickPins();
|
stopJoystickPins();
|
||||||
#endif /* HAL_USE_PAL && EFI_JOYSTICK */
|
#endif /* HAL_USE_PAL && EFI_JOYSTICK */
|
||||||
|
|
||||||
enginePins.stopInjectionPins();
|
enginePins.stopInjectionPins();
|
||||||
enginePins.stopIgnitionPins();
|
enginePins.stopIgnitionPins();
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
|
|
|
@ -46,6 +46,8 @@ brain_pin_e getSckPin(spi_device_e device);
|
||||||
|
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "debounce.h"
|
||||||
|
|
||||||
void applyNewHardwareSettings(void);
|
void applyNewHardwareSettings(void);
|
||||||
void initHardware(Logging *logging);
|
void initHardware(Logging *logging);
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
@ -53,5 +55,6 @@ void initHardware(Logging *logging);
|
||||||
void showBor(void);
|
void showBor(void);
|
||||||
void setBor(int borValue);
|
void setBor(int borValue);
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
class ButtonDebounce;
|
||||||
|
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
Loading…
Reference in New Issue