setup-loop.cpp 586 B

123456789101112131415161718192021222324252627
  1. #include "all-headers.h"
  2. int ultimate_answer(42);
  3. bool clickHappened(false);
  4. void setup (USER_MODE) {
  5. // Enable interruption triggered by encoder clic
  6. PORTD_PCR (0) |= PORT_PCR_IRQC (10);
  7. NVIC_ENABLE_IRQ (ISRSlot::PORTD);
  8. }
  9. void loop (USER_MODE) {
  10. assertion (ultimate_answer == 42, 101, __FILE__, __LINE__) ;
  11. if (clickHappened) {
  12. printString(MODE_ "Clic! ");
  13. clickHappened = false;
  14. }
  15. }
  16. void clicInterruptSection(SECTION_MODE) {
  17. clickHappened = true;
  18. // Acquit interruption
  19. PORTD_PCR (0) |= PORT_PCR_ISF ;
  20. const uint32_t x __attribute__((unused)) = PORTD_PCR (0) ;
  21. }