check if pin has changed and initialise gpio event callback
| 23 | |
| 24 | // check if pin has changed and initialise gpio event callback |
| 25 | void AP_WheelEncoder_Quadrature::update_pin(uint8_t &pin, |
| 26 | uint8_t new_pin, |
| 27 | uint8_t &pin_value) |
| 28 | { |
| 29 | if (new_pin == pin) { |
| 30 | // no change |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | // remove old gpio event callback if present |
| 35 | if (pin != (uint8_t)-1 && |
| 36 | !hal.gpio->detach_interrupt(pin)) { |
| 37 | GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "WEnc: Failed to detach from pin %u", pin); |
| 38 | // ignore this failure or the user may be stuck |
| 39 | } |
| 40 | |
| 41 | pin = new_pin; |
| 42 | |
| 43 | // install interrupt handler on rising or falling edge of gpio for pin a |
| 44 | if (new_pin != (uint8_t)-1) { |
| 45 | hal.gpio->pinMode(pin, HAL_GPIO_INPUT); |
| 46 | if (!hal.gpio->attach_interrupt( |
| 47 | pin, |
| 48 | FUNCTOR_BIND_MEMBER(&AP_WheelEncoder_Quadrature::irq_handler, |
| 49 | void, |
| 50 | uint8_t, |
| 51 | bool, |
| 52 | uint32_t), |
| 53 | AP_HAL::GPIO::INTERRUPT_BOTH)) { |
| 54 | GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "WEnc: Failed to attach to pin %u", pin); |
| 55 | } |
| 56 | pin_value = hal.gpio->read(pin); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void AP_WheelEncoder_Quadrature::update(void) |
| 61 | { |
nothing calls this directly
no test coverage detected