[riot-notifications] [RIOT-OS/RIOT] cpu/stm32/qdec: test null callback pointer (#14125)

benpicco notifications at github.com
Sun May 24 01:55:56 CEST 2020


How about instead we do

```patch
--- a/cpu/stm32/periph/qdec.c
+++ b/cpu/stm32/periph/qdec.c
@@ -113,8 +113,12 @@ int32_t qdec_init(qdec_t qdec, qdec_mode_t mode, qdec_cb_t cb, void *arg)
     isr_ctx[qdec].arg = arg;
 
     /* Enable the qdec's interrupt */
-    NVIC_EnableIRQ(qdec_config[qdec].irqn);
-    dev(qdec)->DIER |= TIM_DIER_UIE;
+    if (cb) {
+        NVIC_EnableIRQ(qdec_config[qdec].irqn);
+        dev(qdec)->DIER |= TIM_DIER_UIE;
+    } else {
+        dev(qdec)->DIER &= ~TIM_DIER_UIE;
+    }
 
     /* Reset counter and start qdec */
     qdec_start(qdec);
```

So the interrupt doesn't get enabled in the first place if no callback is registered.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/14125#issuecomment-633155635
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20200523/5160378c/attachment.htm>


More information about the notifications mailing list