+ debug_setstate(1);
+ log_buffer_count = 0;
+}
+
+static void log_word(uint16_t word) {
+ if (log_buffer_count == LOG_BUFFER) {
+ debug_setstate(0x42);
+ log_buffer_count++;
+ }
+ if (log_buffer_count >= LOG_BUFFER)
+ return;
+
+ eeprom_write_word(&log_buffer[log_buffer_count], word);
+ log_buffer_count++;
+}
+
+/* ------------ Timer ----------- */
+
+uint16_t clock = 0;
+
+static void inline init_tmr()
+{
+ TCCR0A = _BV(WGM00);
+ TCCR0B = _BV(CS02) | _BV(CS00); // 1 kHz
+ OCR0A = 10; // 100 Hz
+ TIMSK |= _BV(OCIE0A);
+ DDRA |= _BV( PA0 );
+
+ clock = 0;
+}
+
+static void inline tmr_handler()
+{
+ unsigned char c = clock & 0x7F;
+ ++clock;
+
+ if (c == 10 || c == 30)
+ led_on();
+
+ if (c == 20 || c == 40)
+ led_off();
+
+ log_word(adcval);
+ if (adcval != 0xFFEE) {
+ adcval = 0xFFEE;
+
+ ADCSRA |= _BV(ADIE) | _BV(ADSC);
+ }