]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - ps2_vusb/main.c
refactor keyboard.h, host.h
[max/tmk_keyboard.git] / ps2_vusb / main.c
index 359e28254e4b04c78920d7a76ecc1f4f05f316ad..74c7a17e0d8a2b878345f2e0b4aafe67b4052b13 100644 (file)
@@ -7,68 +7,54 @@
  * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
  */
-
-/*
-This example should run on most AVRs with only little changes. No special
-hardware resources except INT0 are used. You may have to change usbconfig.h for
-different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
-at least be connected to INT0 as well.
-
-We use VID/PID 0x046D/0xC00E which is taken from a Logitech mouse. Don't
-publish any hardware using these IDs! This is for demonstration only!
-*/
-
 #include <stdint.h>
 #include <avr/io.h>
 #include <avr/wdt.h>
 #include <avr/interrupt.h>  /* for sei() */
-#include <util/delay.h>     /* for _delay_ms() */
-
 #include <avr/pgmspace.h>   /* required by usbdrv.h */
+#include <util/delay.h>     /* for _delay_ms() */
 #include "usbdrv.h"
 #include "usart_print.h"        /* This is also an example for using debug macros */
-#include "ps2.h"
 #include "usb_keycodes.h"
 #include "matrix_skel.h"
 #include "keymap_skel.h"
+#include "mousekey.h"
 #include "layer.h"
 #include "print.h"
 #include "debug.h"
 #include "sendchar.h"
-#include "keyboard.h"
+#include "host.h"
+#include "host_vusb.h"
 #include "timer.h"
+#include "led.h"
+#include "keyboard.h"
 
-/* ------------------------------------------------------------------------- */
-/* ----------------------------- USB interface ----------------------------- */
-/* ------------------------------------------------------------------------- */
-
-
-
-
-
+#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
+#define DEBUGP(x) do { PORTC = x; } while (0)
 
+//static uint8_t last_led = 0;
 int main(void)
 {
-uchar   i;
-
-print_enable = true;
-debug_enable = true;
-timer_init();
-matrix_init();
-
+    DEBUGP_INIT();
     wdt_enable(WDTO_1S);
     /* Even if you don't use the watchdog, turn it off here. On newer devices,
      * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
      */
+
     /* RESET status: all port bits are inputs without pull-up.
      * That's the way we need D+ and D-. Therefore we don't need any
      * additional hardware initialization.
      */
     odDebugInit();
-    DBG1(0x00, 0, 0);       /* debug output: main starts */
     usbInit();
-    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
-    i = 0;
+
+    print_enable = true;
+    //debug_enable = true;
+    keyboard_init();
+
+    /* enforce re-enumeration, do this while interrupts are disabled! */
+    usbDeviceDisconnect();
+    uint8_t i = 0;
     while(--i){             /* fake USB disconnect for > 250 ms */
         wdt_reset();
         _delay_ms(1);
@@ -76,51 +62,58 @@ matrix_init();
     usbDeviceConnect();
     sei();
 
-    uint8_t fn_bits = 0;
+    //uint8_t fn_bits = 0;
     while (1) {                /* main event loop */
-        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
+        DEBUGP(0x01);
         wdt_reset();
         usbPoll();
+        host_vusb_keyboard_send();
 
+        DEBUGP(0x02);
+        keyboard_proc();
+        DEBUGP(0x03);
 /*
-static uint8_t code = 0;
-code = ps2_host_recv();
-if (code) {
-    odDebug(0x05, &code, 1);
-}
-*/
         matrix_scan();
-        if (matrix_is_modified()) {
-            //matrix_print();   // too heavy on USART
-            fn_bits = 0;
-            report_swap();
-            report_clear();
-            for (int row = 0; row < matrix_rows(); row++) {
-                for (int col = 0; col < matrix_cols(); col++) {
-                    if (!matrix_is_on(row, col)) continue;
-
-                    uint8_t code = layer_get_keycode(row, col);
-                    if (code == KB_NO) {
-                        // do nothing
-                    }
-                    else if (IS_MOD(code)) {
-                        report_add_mod(MOD_BIT(code));
-                    }
-                    else if (IS_KEY(code)) {
-                        report_add_key(code);
-                    }
-                    else if (IS_FN(code)) {
-                        fn_bits |= FN_BIT(code);
-                    }
-                    else {
-                        debug("ignore keycode: "); debug_hex(code); debug("\n");
-                    }
+        fn_bits = 0;
+        host_swap_keyboard_report();
+        host_clear_keyboard_report();
+        mousekey_clear_report();
+        for (int row = 0; row < matrix_rows(); row++) {
+            for (int col = 0; col < matrix_cols(); col++) {
+                if (!matrix_is_on(row, col)) continue;
+
+                uint8_t code = layer_get_keycode(row, col);
+                if (code == KB_NO) {
+                    // do nothing
+                }
+                else if (IS_MOD(code)) {
+                    host_add_mod_bit(MOD_BIT(code));
+                }
+                else if (IS_KEY(code)) {
+                    host_add_key(code);
+                }
+                else if (IS_FN(code)) {
+                    fn_bits |= FN_BIT(code);
+                }
+                else if (IS_MOUSEKEY(code)) {
+                    mousekey_decode(code);
+                }
+                else {
+                    debug("ignore keycode: "); debug_hex(code); debug("\n");
                 }
             }
         }
+        DEBUGP(0x03);
         layer_switching(fn_bits);
         if (matrix_is_modified()) {
-            report_send();
+            host_send_keyboard_report();
+        }
+        mousekey_send();
+
+        if (last_led != host_keyboard_led()) {
+            led_set(host_keyboard_led());
+            last_led = host_keyboard_led();
         }
+*/
     }
 }