You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uClock/src/platforms/rp2040.h

30 lines
1.0 KiB

#include <Arduino.h>
#include "pico/sync.h"
// RPi-specific timer
struct repeating_timer timer;
#define ATOMIC(X) { uint32_t __interrupt_mask = save_and_disable_interrupts(); X; restore_interrupts(__interrupt_mask); }
// forward declaration of uClockHandler
void uClockHandler();
// ISR handler -- called when tick happens
bool handlerISR(repeating_timer *timer)
{
uClockHandler();
return true;
}
void initTimer(uint32_t init_clock) {
// set up RPi interrupt timer
// todo: actually should be -init_clock so that timer is set to start init_clock us after last tick, instead of init_clock us after finished processing last tick!
add_repeating_timer_us(init_clock, &handlerISR, NULL, &timer);
}
void setTimer(uint32_t us_interval) {
cancel_repeating_timer(&timer);
// todo: actually should be -us_interval so that timer is set to start init_clock us after last tick, instead of init_clock us after finished processing last tick!
add_repeating_timer_us(us_interval, &handlerISR, NULL, &timer);
}