mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-21 15:34:33 +08:00
Change debounce logic so less is done in interrupts
This commit is contained in:
@@ -10,6 +10,9 @@ static void endstop_cb_wrapper(void* ctx){
|
||||
}
|
||||
|
||||
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);
|
||||
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
|
||||
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
|
||||
@@ -28,11 +31,7 @@ bool Endstop::getEndstopState() {
|
||||
}
|
||||
|
||||
void Endstop::endstop_cb() {
|
||||
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
|
||||
GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num);
|
||||
|
||||
debounce_timer_ = axis_->loop_counter_ * current_meas_period;
|
||||
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
|
||||
}
|
||||
|
||||
void Endstop::set_endstop_enabled(bool enable){
|
||||
|
||||
@@ -23,6 +23,7 @@ class Endstop {
|
||||
|
||||
bool getEndstopState();
|
||||
|
||||
|
||||
bool endstop_state_ = false;
|
||||
|
||||
auto make_protocol_definitions(){
|
||||
@@ -41,6 +42,6 @@ class Endstop {
|
||||
private:
|
||||
|
||||
bool pin_state_ = false;
|
||||
float debounce_timer_ = 0;
|
||||
volatile float debounce_timer_ = 0;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user