raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.26k stars 838 forks source link

Add a function that returns the remaining time before an alarm trigger #1628

Open TheRaf974 opened 5 months ago

TheRaf974 commented 5 months ago

I'ld like to make a PR to add function that returns the remaining time before an alarm trigger.

I'm using an alarm to add a cooldown to an input button that'll be used by people. At the beginning, I was manually checking the difference of time with the last use of the button but it looked better to me to use a timer.

However, if someone press the button while in cooldown, I would like to let him know the time remaining before the button can be pressed effectively.

Looking in the RP2040 datasheet chapter 4.6.3, I found we can get the remaining time with something like : timer_hw->alarm[alarm_pool] - timer_hw->timerawl

I think there might be situations where a function like this can be useful. Also, my code may needs somes adjustements.