From 180e1cb7b63dc1d911255c6ab5bb55e40efd4248 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 7 Oct 2015 01:08:31 +0100 Subject: [PATCH] SPRacingF3Mini - Quick hack to allow configuration to be reset when holding buttons A and B down for 5 seconds when powering on. --- src/main/main.c | 35 +++++++++++++++++++++++++ src/main/target/SPRACINGF3MINI/target.h | 10 ++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index 008713585..09a327a20 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -193,6 +193,41 @@ void init(void) ledInit(false); #endif +#ifdef SPRACINGF3MINI + gpio_config_t buttonAGpioConfig = { + BUTTON_A_PIN, + Mode_IPU, + Speed_2MHz + }; + gpioInit(BUTTON_A_PORT, &buttonAGpioConfig); + + gpio_config_t buttonBGpioConfig = { + BUTTON_B_PIN, + Mode_IPU, + Speed_2MHz + }; + gpioInit(BUTTON_B_PORT, &buttonBGpioConfig); + + // Check status of bind plug and exit if not active + delayMicroseconds(10); // allow GPIO configuration to settle + + if (!isMPUSoftReset()) { + uint8_t secondsRemaining = 5; + bool bothButtonsHeld; + do { + bothButtonsHeld = !digitalIn(BUTTON_A_PORT, BUTTON_A_PIN) && !digitalIn(BUTTON_B_PORT, BUTTON_B_PIN); + if (bothButtonsHeld) { + if (--secondsRemaining == 0) { + resetEEPROM(); + systemReset(); + } + delay(1000); + LED0_TOGGLE; + } + } while (bothButtonsHeld); + } +#endif + #ifdef SPEKTRUM_BIND if (feature(FEATURE_RX_SERIAL)) { switch (masterConfig.rxConfig.serialrx_provider) { diff --git a/src/main/target/SPRACINGF3MINI/target.h b/src/main/target/SPRACINGF3MINI/target.h index f34affbc5..767800a0e 100644 --- a/src/main/target/SPRACINGF3MINI/target.h +++ b/src/main/target/SPRACINGF3MINI/target.h @@ -180,12 +180,16 @@ #define USE_SERVOS #define USE_CLI +#define BUTTON_A_PORT GPIOB +#define BUTTON_A_PIN Pin_1 +#define BUTTON_B_PORT GPIOB +#define BUTTON_B_PIN Pin_0 + #define SPEKTRUM_BIND // USART3, #define BIND_PORT GPIOB #define BIND_PIN Pin_11 #define HARDWARE_BIND_PLUG -// Hardware bind plug at PB1 -#define BINDPLUG_PORT GPIOB -#define BINDPLUG_PIN Pin_1 +#define BINDPLUG_PORT BUTTON_B_PORT +#define BINDPLUG_PIN BUTTON_B_PIN