]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk.c
revise Fn key processing.
[max/tmk_keyboard.git] / tmk.c
diff --git a/tmk.c b/tmk.c
index 54b02fcbc96b973450093e85c123ffd74fbfa7ba..53da9aa8604ae37d7b433b2bc23754b4b4cf78b4 100644 (file)
--- a/tmk.c
+++ b/tmk.c
  * THE SOFTWARE.
  */
 
-// TODO: clean unused headers
 #include <stdbool.h>
 #include <avr/io.h>
-#include <avr/pgmspace.h>
 #include <avr/interrupt.h>
 #include <util/delay.h>
 #include "usb.h"
-#include "usb_keyboard.h"
-#include "usb_mouse.h"
-#include "print.h"
 #include "matrix_skel.h"
-#include "keymap.h"
-#include "jump_bootloader.h"
-
 #include "key_process.h"
+#include "print.h"
+#include "debug.h"
+#include "util.h"
+#include "controller.h"
+#include "timer.h"
 
-#define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
 
-// TODO: should go to hardware dependent file
-// for Teensy/Teensy++ 2.0
-#define LED_CONFIG    (DDRD |= (1<<6))
-#define LED_ON        (PORTD |= (1<<6))
-#define LED_OFF       (PORTD &= ~(1<<6))
+#define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
 
 
-uint16_t idle_count=0;
+bool debug_enable = false;
+bool debug_matrix = false;
+bool debug_keyboard = false;
+bool debug_mouse = false;
 
 
 int main(void)
@@ -63,43 +58,35 @@ int main(void)
     usb_init();
     while (!usb_configured()) /* wait */ ;
 
-    // Configure timer 0 to generate a timer overflow interrupt every
-    // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
-    // This demonstrates how to use interrupts to implement a simple
-    // inactivity timeout.
-    TCCR0A = 0x00;
-    TCCR0B = 0x05;
-    TIMSK0 = (1<<TOIE0);
-
+    timer_init();
 
     matrix_init();
     matrix_scan();
-    // debug on when 4 keys are pressed
-    if (matrix_key_count() == 4) print_enable = true;
+    // debug on by pressing down any 4 or more keys during boot time.
+    if (matrix_key_count() >= 4) {
+        print_enable = true;
+        debug_enable = true;
+    }
 
-    /* wait for debug pipe to print greetings. */
+    /* wait for debug pipe ready */
     if (print_enable) {
-        for (int i =0; i < 6; i++) {
-            LED_CONFIG;
-            LED_ON;
+#ifdef DEBUG_LED
+        for (int i = 0; i < 6; i++) {
+            DEBUG_LED_CONFIG;
+            DEBUG_LED_ON;
             _delay_ms(500);
-            LED_OFF;
+            DEBUG_LED_OFF;
             _delay_ms(500);
         }
+#else
+            _delay_ms(6000);
+#endif
     }
-    print("\nt.m.k. keyboard 1.2\n");
+    // print description
+    print(STR(DESCRIPTION) "\n");
+
     while (1) {
        proc_matrix(); 
         _delay_ms(2);
     }
 }
-
-
-// This interrupt routine is run approx 61 times per second.
-// A very simple inactivity timeout is implemented, where we
-// will send a space character and print a message to the
-// hid_listen debug message window.
-ISR(TIMER0_OVF_vect)
-{
-    idle_count++;
-}