[riot-notifications] [RIOT-OS/RIOT] periph/gpio: add gpio_set_cb() function (#12082)

Marian Buschsieweke notifications at github.com
Tue Sep 17 14:19:58 CEST 2019

maribu commented on this pull request.

> @@ -416,6 +416,25 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
     return 0;
+int gpio_set_cb(gpio_t pin, gpio_cb_t cb, void *arg)
+    int8_t int_num = _int_num(pin);
+    if (int_num < 0) {
+        return -1;
+    }
+    if (cb) {
+        config[int_num].cb = cb;
+    }
+    if (arg) {
+        config[int_num].arg = arg;
+    }

> How about a driver that gets context info via driver_t *ctx = arg; in more than one ISR handler, but changes the callback along with going through its state machine? (I can see myself doing that...)

But that driver will certainly have access to the context anyway, and can thus just provide that argument again.

There definitely needs to be a way to set the argument to `NULL`. It is hard to image a scenario in which the callback does different things depending on the parameter, with `NULL` being a special case.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190917/7168894c/attachment.htm>

More information about the notifications mailing list