From 8dc86e5ec58ec94f7ea8227ee008ded202c4204f Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 26 Feb 2025 14:26:28 -0700 Subject: libhw: Add rp2040_gpioirq, use it --- libhw/rp2040_gpioirq.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libhw/rp2040_gpioirq.h (limited to 'libhw/rp2040_gpioirq.h') diff --git a/libhw/rp2040_gpioirq.h b/libhw/rp2040_gpioirq.h new file mode 100644 index 0000000..06041c9 --- /dev/null +++ b/libhw/rp2040_gpioirq.h @@ -0,0 +1,33 @@ +/* libhw/rp2040_gpioirq.h - Utilities for sharing the GPIO IRQ (IO_IRQ_BANK0) + * + * Copyright (C) 2025 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBHW_RP2040_GPIOIRQ_H_ +#define _LIBHW_RP2040_GPIOIRQ_H_ + +#include /* for enum gpio_irq_level */ + +typedef void (*gpioirq_handler_t)(void *arg, uint gpio, enum gpio_irq_level event); + +/** + * Register `fn(arg, ...)` to be called when `event` fires on GPIO pin + * `gpio`. + * + * If multiple events happen close together, the handlers will not + * necessarily be called in-order. + * + * Your handler does not need to acknowledge the IRQ; that will be + * done for you after your handler is called. + * + * It is illegal to call gpioirq_set_and_enable_exclusive_handler() + * on multiple cores. + * + * This is better than the Pico-SDK IRQ functions + * because their functions call the handlers for every event, and it + * is up to you to de-mux them in your handler. + */ +void gpioirq_set_and_enable_exclusive_handler(uint gpio, enum gpio_irq_level event, gpioirq_handler_t fn, void *arg); + +#endif /* _LIBHW_RP2040_GPIOIRQ_H_ */ -- cgit v1.2.3-2-g168b