]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - protocol/pjrc/main.c
Merge pull request #148 from cub-uanic/patch-1
[max/tmk_keyboard.git] / protocol / pjrc / main.c
index 15f14920b4b4514b62bda24d19790b142b83bf25..4f87a1736458851e980b9839da15e336ed770ce9 100644 (file)
 #include <stdbool.h>
 #include <avr/io.h>
 #include <avr/interrupt.h>
+#include <avr/wdt.h>
 #include <util/delay.h>
 #include "keyboard.h"
 #include "usb.h"
 #include "matrix.h"
 #include "print.h"
 #include "debug.h"
+#include "sendchar.h"
 #include "util.h"
-#include "bootloader.h"
-#ifdef PS2_MOUSE_ENABLE
-#   include "ps2_mouse.h"
-#endif
+#include "suspend.h"
 #include "host.h"
 #include "pjrc.h"
 
 #define CPU_PRESCALE(n)    (CLKPR = 0x80, CLKPR = (n))
 
 
-bool debug_enable = false;
-bool debug_matrix = false;
-bool debug_keyboard = false;
-bool debug_mouse = false;
-
-
 int main(void)
 {
-    DEBUG_LED_CONFIG;
-    DEBUG_LED_OFF;
-
     // set for 16 MHz clock
     CPU_PRESCALE(0);
 
@@ -62,36 +52,21 @@ int main(void)
     usb_init();
     while (!usb_configured()) /* wait */ ;
 
-    keyboard_init();
-    matrix_scan();
-    if (matrix_key_count() >= 3) {
-#ifdef DEBUG_LED
-        for (int i = 0; i < 6; i++) {
-            DEBUG_LED_CONFIG;
-            DEBUG_LED_ON;
-            _delay_ms(500);
-            DEBUG_LED_OFF;
-            _delay_ms(500);
-        }
-#else
-        _delay_ms(5000);
-#endif
-        print_enable = true;
-        debug_enable = true;
-        debug_matrix = true;
-        debug_keyboard = true;
-        debug_mouse = true;
-        print("debug enabled.\n");
-    }
-    if (matrix_key_count() >= 4) {
-        print("jump to bootloader...\n");
-        _delay_ms(1000);
-        bootloader_jump(); // not return
-    }
-
+    print_set_sendchar(sendchar);
 
+    keyboard_init();
     host_set_driver(pjrc_driver());
+#ifdef SLEEP_LED_ENABLE
+    sleep_led_init();
+#endif
     while (1) {
-       keyboard_proc(); 
+        while (suspend) {
+            suspend_power_down(WDTO_120MS);
+            if (remote_wakeup && suspend_wakeup_condition()) {
+                usb_remote_wakeup();
+            }
+        }
+
+        keyboard_task(); 
     }
 }