From 3f49a57b99e7fe5aafa73e70ed146d98b1ae174c Mon Sep 17 00:00:00 2001
From: "Luke T. Shumaker" <lukeshu@lukeshu.com>
Date: Mon, 24 Feb 2025 22:54:30 -0700
Subject: libhw: rp2040_hwspi: Use interrupts instead of busy-polling

---
 libhw/rp2040_dma.h | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

(limited to 'libhw/rp2040_dma.h')

diff --git a/libhw/rp2040_dma.h b/libhw/rp2040_dma.h
index e4b44ff..c8d69b1 100644
--- a/libhw/rp2040_dma.h
+++ b/libhw/rp2040_dma.h
@@ -31,13 +31,26 @@ enum dma_channel_transfer_size {
     DMA_SIZE_32 = 2    ///< Word transfer (32 bits)
 };
 
-static inline bool dma_channel_is_busy(uint channel) {
-	assert(channel < NUM_DMA_CHANNELS);
-	return dma_hw->ch[channel].al1_ctrl & DMA_CH0_CTRL_TRIG_BUSY_BITS;
-}
-
 /* Our own code ***************************************************************/
 
+enum dmairq {
+	DMAIRQ_0 = DMA_IRQ_0,
+	DMAIRQ_1 = DMA_IRQ_1,
+};
+
+typedef void (*dmairq_handler_t)(void *arg, enum dmairq irq, uint channel);
+
+/**
+ * Register `fn(arg, ...)` to be called when `channel` completes or
+ * has a NULL trigger (depending on the channel's configuration).
+ *
+ * Your handler does not need to acknowledge the IRQ; that will be
+ * done for you after your handler is called.
+ *
+ * It is illegal to enable the same channel on more than one IRQ.
+ */
+void dmairq_set_and_enable_exclusive_handler(enum dmairq irq, uint channel, dmairq_handler_t fn, void *arg);
+
 #define DMA_CTRL_ENABLE          (1<<0)
 #define DMA_CTRL_HI_PRIO         (1<<1)
 #define DMA_CTRL_DATA_SIZE(sz)   ((sz)<<2)
-- 
cgit v1.2.3-2-g168b