MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / update_pin

Method update_pin

libraries/AP_WheelEncoder/WheelEncoder_Quadrature.cpp:25–58  ·  view source on GitHub ↗

check if pin has changed and initialise gpio event callback

Source from the content-addressed store, hash-verified

23
24// check if pin has changed and initialise gpio event callback
25void 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
60void AP_WheelEncoder_Quadrature::update(void)
61{

Callers

nothing calls this directly

Calls 4

detach_interruptMethod · 0.80
pinModeMethod · 0.45
attach_interruptMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected