#include "all-headers.h"

int ultimate_answer(42);
uint32_t clicCounter(0);

void setup (USER_MODE) {
	// Enable interruption triggered by encoder clic
	PORTD_PCR (0) |= PORT_PCR_IRQC (10);
	NVIC_ENABLE_IRQ (ISRSlot::PORTD);
}

void loop (USER_MODE) {
	assertion (ultimate_answer == 42, 101, __FILE__, __LINE__) ;

	if (clicCounter > 0) {
		gotoLineColumn(MODE_ 0, 0);
		printString(MODE_ "Clic");
	}
}

void clicInterruptSection(SECTION_MODE) {
	clicCounter ++;

	// Acquit interruption
	PORTD_PCR (0) |= PORT_PCR_ISF ;
	const uint32_t x __attribute__((unused)) = PORTD_PCR (0) ;
}