From 85fdb1bbac20c2e2a4b6a1a10b3f7fde68ff9db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 25 Jul 2022 15:40:56 +0200 Subject: [PATCH] app: fix dial homing --- application.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application.c b/application.c index 7543fc1..d99e40a 100644 --- a/application.c +++ b/application.c @@ -72,7 +72,7 @@ static int8_t drv8825_direction = 0; /**< direction of the steps (1 = clockwise, #define DRV8825_SPEED_LIMIT 420U // dials position info -#define DIAL_SWITCH_PIN PB3 /**< pin connected to reed switch, pulled low when the hour dial is nearby */ +#define DIAL_SWITCH_PIN PB4 /**< pin connected to reed switch, connected to ground when the hour dial is nearby */ #define DIAL_CYCLE_STEPS 11904U /**< number of steps for the hour dial to make a round */ #define DIAL_MIDNIGHT_STEPS 6557U /**< number of steps after dial detection for dials to show midnight */ static volatile uint32_t dial_steps = 0; /**< set to drv8825_steps when dial is nearby */ @@ -972,6 +972,7 @@ void main(void) gpio_mode_setup(GPIO_PORT(DIAL_SWITCH_PIN), GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN(DIAL_SWITCH_PIN)); // set GPIO to input and pull up exti_select_source(GPIO_EXTI(DIAL_SWITCH_PIN), GPIO_PORT(DIAL_SWITCH_PIN)); // mask external interrupt of this pin only for this port exti_set_trigger(GPIO_EXTI(DIAL_SWITCH_PIN), EXTI_TRIGGER_FALLING); // trigger when magnet on dial is nearby + exti_reset_request(GPIO_EXTI(DIAL_SWITCH_PIN)); // ensure the interrupt flag is cleared exti_enable_request(GPIO_EXTI(DIAL_SWITCH_PIN)); // enable external interrupt nvic_enable_irq(GPIO_NVIC_EXTI_IRQ(DIAL_SWITCH_PIN)); // enable interrupt puts_debug("OK\n"); @@ -1224,6 +1225,10 @@ void TIM_ISR(DRV8825_STEP_TIMER)(void) void GPIO_EXTI_ISR(DIAL_SWITCH_PIN)(void) { exti_reset_request(GPIO_EXTI(DIAL_SWITCH_PIN)); // reset interrupt + // I don't know why, but the RGBMATRIX_ISR does trigger this EXTI + if (gpio_get(GPIO_PORT(DIAL_SWITCH_PIN), GPIO_PIN(DIAL_SWITCH_PIN))) { // be sure the pin is actually low + return; + } if (drv8825_steps > dial_steps + 1000) { // ignore going away debounce dial_steps = drv8825_steps; // remember on which step we are drv8825_steps = 0; // restart step counter