 //   D7 (AIN1) : Analog comparator negative input. (voltage to compare)
 //   D9 (PWM)  : Constant reference PWM voltage for brightness threshold.
 
-#if defined(__MK20DX256__) // Teensy 3.1
-
-// No library exists for Freescale MK20DX256 processor's 
-// built-in CMP module, so we need to do it in low level...
-#define CMP_SCR_DMAEN   ((uint8_t)0x40) // DMA Enable Control
-#define CMP_SCR_IER     ((uint8_t)0x10) // Comparator Interrupt Enable Rising
-#define CMP_SCR_IEF     ((uint8_t)0x08) // Comparator Interrupt Enable Falling
-#define CMP_SCR_CFR     ((uint8_t)0x04) // Analog Comparator Flag Rising
-#define CMP_SCR_CFF     ((uint8_t)0x02) // Analog Comparator Flag Falling
-#define CMP_SCR_COUT    ((uint8_t)0x01) // Analog Comparator Output
-
-#elif defined(REL_GR_KURUMI) // GR-KURUMI
+#if defined(REL_GR_KURUMI) // GR-KURUMI
 
 // Renesas RL78/G13 has 10 external interrupts (INTP0-INTP6, INTP8, INTP9, INTKR)
 // but GR-KURUMI made all of these pins unusable except

void _resetCMP()
{
  // prepare capturing video frames.
  // set the reference analog voltage.
  analogWriteResolution(12);
  analogWrite(A14, brightnessThreshold);

  // set CMP1 interrupt vector before enabling CMP1
  NVIC_SET_PRIORITY(IRQ_CMP1, 64); // 0 = highest priority, 255 = lowest
  NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
  
  // comparator settings  
  SIM_SCGC4 |= SIM_SCGC4_CMP; // comparator clock set on. it is off by default for conserving power.
  CORE_PIN23_CONFIG = PORT_PCR_MUX(0); // pin function set to comparator
  CMP1_CR1 = 0; // set CMP1_CR1 to a known state
  CMP1_CR0 = 0; // set CMP1_CR0 to a known state
  CMP1_CR1   = B00000001; // enable comparator
  CMP1_MUXCR = B00011000; // set comparator input PSEL=IN3 (DAC0_OUT) / MSEL=IN0 (D23)
  CMP1_SCR   = CMP_SCR_IER | CMP_SCR_IEF; // set triggering edge to both rising and falling.
}

#elif defined(REL_GR_KURUMI) // GR-KURUMI


#else // Arduino Pro Mini

#if F_CPU == 16000000
const int SCANLINE_OFFSET = 110;
const int MAX_SCANLINES = 70;
typedef uint16_t image_t; // 1 word = 16 bits
#define SIZE_OF_IMAGE_T 2
// overclocked Arduino Pro Mini
// GoPro needs 3.3V logic. Running 16MHz on ATmega 328P is not recommended at 3.3V.
// (Note: ATmega 328P can run 20MHz but it is not supported by Arduino IDE)
const int WORD_PER_LINE = 1; // 2^1 words = 32 bits
#else // F_CPU == 8000000
const int SCANLINE_OFFSET = 94;
const int MAX_SCANLINES = 100;
typedef uint16_t image_t; // 1 word = 16 bits
#define SIZE_OF_IMAGE_T 2
const int WORD_PER_LINE = 0; // 2^0 words = 16 bits
#endif

// set brightnessThreshold between 23: very sensitive and 77: not sensitive.
const int brightnessThreshold = 50; // CHANGE ME!!
