From d90793b788e707372d4cc4749739f201f229450c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 8 Jan 2019 23:22:12 -0500 Subject: [PATCH] Remove interrupt-based Endstop switching --- Firmware/MotorControl/endstop.cpp | 22 +++++----------------- Firmware/MotorControl/endstop.hpp | 1 - 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/Firmware/MotorControl/endstop.cpp b/Firmware/MotorControl/endstop.cpp index 4443fdd6..d01c361b 100644 --- a/Firmware/MotorControl/endstop.cpp +++ b/Firmware/MotorControl/endstop.cpp @@ -5,14 +5,14 @@ Endstop::Endstop(Endstop::Config_t &config) set_endstop_enabled(config_.enabled); } -static void endstop_cb_wrapper(void* ctx){ - reinterpret_cast(ctx)->endstop_cb(); -} - void Endstop::update() { uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num); GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num); + auto last_pin_state = pin_state_; pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin); + if(pin_state_ != last_pin_state){ + debounce_timer_ = axis_->loop_counter_ * current_meas_period; + } if (config_.enabled) { float now = axis_->loop_counter_ * current_meas_period; if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001f)) { // Debounce timer expired, take the new pin state @@ -30,10 +30,6 @@ bool Endstop::getEndstopState() { return endstop_state_; } -void Endstop::endstop_cb() { - debounce_timer_ = axis_->loop_counter_ * current_meas_period; -} - void Endstop::set_endstop_enabled(bool enable){ uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num); GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num); @@ -42,15 +38,7 @@ void Endstop::set_endstop_enabled(bool enable){ GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = gpio_pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pull = config_.is_active_high ? GPIO_PULLDOWN : GPIO_PULLUP;; HAL_GPIO_Init(gpio_port, &GPIO_InitStruct); - - uint32_t pull_up_down = config_.is_active_high ? GPIO_PULLDOWN : GPIO_PULLUP; - uint32_t interrupt_mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_subscribe(gpio_port, gpio_pin, pull_up_down, interrupt_mode, - endstop_cb_wrapper, this); - } - else { - GPIO_unsubscribe(gpio_port, gpio_pin); } } \ No newline at end of file diff --git a/Firmware/MotorControl/endstop.hpp b/Firmware/MotorControl/endstop.hpp index 92ff10d7..9ff3f079 100644 --- a/Firmware/MotorControl/endstop.hpp +++ b/Firmware/MotorControl/endstop.hpp @@ -17,7 +17,6 @@ class Endstop { Axis* axis_ = nullptr; void set_endstop_enabled(bool enable); - void endstop_cb(); void update(); bool getEndstopState();