]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Output/pjrcUSB/output_com.c
Merge remote-tracking branch 'upstream/master'
[kiibohd-controller.git] / Output / pjrcUSB / output_com.c
index aa5f5b0249468997e775e5d53d168b05f31cfe3f..1651222bdaa77fcaa0383a30c4b0a9380557df29 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011-2014 by Jacob Alexander
+/* Copyright (C) 2011-2015 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
@@ -33,7 +33,7 @@
 // USB Includes
 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
 #include "avr/usb_keyboard_serial.h"
-#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_)
+#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
 #include "arm/usb_dev.h"
 #include "arm/usb_keyboard.h"
 #include "arm/usb_serial.h"
@@ -124,6 +124,11 @@ USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None;
 // count until idle timeout
          uint8_t  USBKeys_Idle_Count = 0;
 
+// Indicates whether the Output module is fully functional
+// 0 - Not fully functional, 1 - Fully functional
+// 0 is often used to show that a USB cable is not plugged in (but has power)
+         uint8_t  Output_Available = 0;
+
 
 
 // ----- Capabilities -----
@@ -419,7 +424,7 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a
                // It is used to send "nothing" in order to break up sequences of USB Codes
                else if ( key == 0x00 )
                {
-                       USBKeys_Changed |= USBKeyChangeState_All;
+                       USBKeys_Changed |= USBKeyChangeState_MainKeys;
 
                        // Also flush out buffers just in case
                        Output_flushBuffers();
@@ -473,9 +478,11 @@ inline void Output_setup()
 {
        // Initialize the USB, and then wait for the host to set configuration.
        // This will hang forever if USB does not initialize
-       usb_init();
-
-       while ( !usb_configured() );
+       // If no USB cable is attached, does not try and initialize USB
+       if ( usb_init() )
+       {
+               while ( !usb_configured() );
+       }
 
        // Register USB Output CLI dictionary
        CLI_registerDictionary( outputCLIDict, outputCLIDictName );
@@ -497,14 +504,15 @@ inline void Output_send()
        while ( USBKeys_Changed )
                usb_keyboard_send();
 
-       // Clear modifiers and keys
-       USBKeys_Modifiers = 0;
-       USBKeys_Sent      = 0;
+       // Clear keys sent
+       USBKeys_Sent = 0;
 
        // Signal Scan Module we are finished
        switch ( USBKeys_Protocol )
        {
        case 0: // Boot Mode
+               // Clear modifiers only in boot mode
+               USBKeys_Modifiers = 0;
                Scan_finishedWithOutput( USBKeys_Sent <= USB_BOOT_MAX_KEYS ? USBKeys_Sent : USB_BOOT_MAX_KEYS );
                break;
        case 1: // NKRO Mode
@@ -548,7 +556,7 @@ inline int Output_putstr( char* str )
 {
 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
        uint16_t count = 0;
-#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
+#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
        uint32_t count = 0;
 #endif
        // Count characters until NULL character, then send the amount counted