]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - USB/pjrc/usb_com.c
Debugging kishsaver.
[kiibohd-controller.git] / USB / pjrc / usb_com.c
index 6afbbabc7ade39490234a405ae5c1a0a3500e5a9..dad641df719c7affec1c739005e5ef0f05c29e47 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 by Jacob Alexander
+/* Copyright (C) 2011-2013 by Jacob Alexander
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
 // ----- Includes -----
 
 // Compiler Includes
-#include <util/delay.h>
-
-// AVR Includes
+#include <Lib/USBLib.h>
 
 // Project Includes
-#include "usb_keyboard_debug.h"
+#include <scan_loop.h>
+
+// USB Includes
+#if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
+#include "avr/usb_keyboard_debug.h"
+#elif defined(_mk20dx128_)
+#include "arm/usb_keyboard.h"
+#include "arm/usb_dev.h"
+#endif
 
 // Local Includes
 #include "usb_com.h"
 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
 volatile uint8_t USBKeys_LEDs = 0;
 
+// protocol setting from the host.  We use exactly the same report
+// either way, so this variable only stores the setting since we
+// are required to be able to report which setting is in use.
+         uint8_t USBKeys_Protocol = 1;
+
+// the idle configuration, how often we send the report to the
+// host (ms * 4) even when it hasn't changed
+         uint8_t USBKeys_Idle_Config = 125;
+
+// count until idle timeout
+         uint8_t USBKeys_Idle_Count = 0;
+
 
 
 // ----- Functions -----
 
 // USB Module Setup
-void usb_setup(void)
+inline void usb_setup(void)
 {
        // Initialize the USB, and then wait for the host to set configuration.
        // If the Teensy is powered without a PC connected to the USB port,
@@ -65,12 +83,12 @@ void usb_setup(void)
 
        // Wait an extra second for the PC's operating system to load drivers
        // and do whatever it does to actually be ready for input
-       _delay_ms(1000);
+       //_delay_ms(1000); // TODO
 }
 
 
 // USB Data Send
-void usb_send(void)
+inline void usb_send(void)
 {
                // TODO undo potentially old keys
                for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
@@ -79,7 +97,11 @@ void usb_send(void)
                // Send keypresses
                usb_keyboard_send();
 
-               // Clear modifiers
+               // Clear modifiers and keys
                USBKeys_Modifiers = 0;
+               USBKeys_Sent      = 0;
+
+               // Signal Scan Module we are finishedA
+               scan_finishedWithUSBBuffer( USBKeys_Sent <= USBKeys_MaxSize ? USBKeys_Sent : USBKeys_MaxSize );
 }