sdmmc_poll: add edge triggered polling support

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 69a36026f89247a076ee8ca5232d068f241e6879
Author: Aidan MacDonald <[email protected]>
Date:   Wed Aug 19 11:07:05 2026 +0100

    sdmmc_poll: add edge triggered polling support
    
    Change-Id: I958a09efc055d474da5e03a06d80719dbb2f5b14

diff --git a/firmware/drivers/sdmmc_poll.c b/firmware/drivers/sdmmc_poll.c
index 4c28e9aea3..1e1d9d5baf 100644
--- a/firmware/drivers/sdmmc_poll.c
+++ b/firmware/drivers/sdmmc_poll.c
@@ -42,7 +42,10 @@ static int sdmmc_poll_timeout(struct timeout *tmo)
         sdmmc_host_set_medium_present(poll->host, true);
     }
 
-    return SDCARD_POLL_TICKS;
+    if (poll->is_polling || (poll->curr_state != poll->last_state))
+        return SDCARD_POLL_TICKS;
+
+    return 0;
 }
 
 void sdmmc_poll_init(struct sdmmc_poll *poll,
@@ -58,7 +61,15 @@ void sdmmc_poll_init(struct sdmmc_poll *poll,
 }
 
 void sdmmc_poll_start(struct sdmmc_poll *poll)
+{
+    poll->is_polling = true;
+    timeout_register(&poll->timeout, sdmmc_poll_timeout,
+                     SDCARD_POLL_TICKS, (intptr_t)poll);
+}
+
+void sdmmc_poll_event(struct sdmmc_poll *poll)
 {
     timeout_register(&poll->timeout, sdmmc_poll_timeout,
                      SDCARD_POLL_TICKS, (intptr_t)poll);
+    sdmmc_poll_timeout(&poll->timeout);
 }
diff --git a/firmware/export/sdmmc_poll.h b/firmware/export/sdmmc_poll.h
index 3472c2b888..3323644e2f 100644
--- a/firmware/export/sdmmc_poll.h
+++ b/firmware/export/sdmmc_poll.h
@@ -32,6 +32,7 @@ struct sdmmc_poll
     bool (*check_inserted)(void);
 
     bool is_inserted;
+    bool is_polling;
     bool last_state;
     bool curr_state;
 };
@@ -42,7 +43,11 @@ struct sdmmc_poll
  * in insertion state is detected via the check_inserted()
  * callback.
  *
- * Call sdmmc_poll_start() to start the poll timer.
+ * Call sdmmc_poll_start() to start the poll timer if you
+ * use level triggered polling.
+ *
+ * To use edge triggered events call sdmmc_poll_event() if
+ * the return value of check_inserted() may have changed.
  *
  * Changes in the insertion state are debounced before they
  * are reported to the sdmmc_host.
@@ -52,5 +57,6 @@ void sdmmc_poll_init(struct sdmmc_poll *poll,
                      struct sdmmc_host *host,
                      bool (*check_inserted) (void));
 void sdmmc_poll_start(struct sdmmc_poll *poll);
+void sdmmc_poll_event(struct sdmmc_poll *poll);
 
 #endif /* __SDMMC_POLL_H__ */
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.