attachinterrupt syntax for WiFi Rev2 TCB0 Periodic Interrupt Timer

There isn't much information online about the internal TCBn interrupts on the WiFi Rev2. In the code below the problem is trying to create a viable attachInterrupt statement. The info I found so far is for interrupts from a pin and the attachInterrupt statement has 3 arguments, pin, ISR, and mode (Change, High etc.) How should it be constructed for the TCB0 timer/counter interrupt in the Periodic Interrupt Timer mode? The one commented out is my latest failed attempt.

void setup()
{
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);              // init built-in led
  
  cli();
  TCB0.CCMP  = 0x11111111;
  TCB0.CTRLA = 0x00000001;
  TCB0.CTRLB = 0x00000000;
  
  //  TCB0.attachInterrupt(0, ISR_PIT, 0);
  
  sei();
}

void loop()
{

}

void ISR_PIT()
{
  Blink();
}

void Blink()
{
  digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ^ 1);
}

Turns out you don't use attachInterrupt for this. Use
ISR(TCB1_INT_vect) instead.

int32_t cnt = 0;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  cli();
  TCB1.CTRLB = TCB_CNTMODE_INT_gc;                      // Periodic Interrupt
  TCB1.CCMP = 25000;                                    // Value to compare with.
  TCB1.INTCTRL = TCB_CAPT_bm;                           // Enable the interrupt
  TCB1.CTRLA = TCB_CLKSEL_CLKDIV1_gc  | TCB_ENABLE_bm;  // div1 prescale, enable timer
  sei();
}

void loop()
{
  if (cnt >= 500)
  {
    cnt = 0;
    Blink();
  }
}

ISR(TCB1_INT_vect)
{
  TCB1.INTFLAGS = TCB_CAPT_bm;                      // Clear interrupt flag
  cnt += 1;
}

void Blink()
{
  digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ^ 1);
}
2 Likes