Toby Chui 2 сар өмнө
parent
commit
acb9e73242

+ 1 - 1
usbkvm/remdeskd_cursor_only/main.go

@@ -16,7 +16,7 @@ import (
 const development = true
 const development = true
 
 
 var (
 var (
-	usbKVMDeviceName  = flag.String("usbkvm", "COM4", "USB KVM device file path")
+	usbKVMDeviceName  = flag.String("usbkvm", "COM6", "USB KVM device file path")
 	usbKVMBaudRate    = flag.Int("baudrate", 115200, "USB KVM baud rate")
 	usbKVMBaudRate    = flag.Int("baudrate", 115200, "USB KVM baud rate")
 	captureDeviceName = flag.String("capture", "/dev/video0", "Video capture device file path")
 	captureDeviceName = flag.String("capture", "/dev/video0", "Video capture device file path")
 	usbKVM            *remdeshid.Controller
 	usbKVM            *remdeshid.Controller

+ 26 - 0
usbkvm/usbkvm_fw/usb_switch.ino

@@ -4,4 +4,30 @@
   This script handle commands that switch the USB mass storage device
   This script handle commands that switch the USB mass storage device
   to the host or slave side
   to the host or slave side
 */
 */
+#include "usbkvm_fw.h"
 
 
+//Entry point for switching USB bus signals, value only support 0x00 (A) and 0x01 (B)
+uint8_t usb_switch_emulation(uint8_t subtype, uint8_t value) {
+  switch (subtype) {
+    case SUBTYPE_SWITCH_USBHID:
+      if (value == 0x00) {
+        digitalWrite(HID_SW_SEL, LOW);
+        return resp_ok;
+      } else if (value == 0x01) {
+        digitalWrite(HID_SW_SEL, HIGH);
+        return resp_ok;
+      }
+      return resp_invalid_key_value;
+    case SUBTYPE_SWITCH_USBMASS:
+      if (value == 0x00) {
+        digitalWrite(USB_SW_SEL, LOW);
+        return resp_ok;
+      } else if (value == 0x01) {
+        digitalWrite(USB_SW_SEL, HIGH);
+        return resp_ok;
+      }
+      return resp_invalid_key_value;
+    default:
+      return resp_invalid_opr_type;
+  }
+}

+ 20 - 16
usbkvm/usbkvm_fw/usbkvm_fw.h

@@ -6,26 +6,26 @@
 #ifndef _usbkvm_
 #ifndef _usbkvm_
 #define _usbkvm_
 #define _usbkvm_
 
 
-/* Hardware Configurations */
+/* ----------- Hardware Configurations -----------*/
 #define MIN_KEY_EVENTS_DELAY 20  //ms
 #define MIN_KEY_EVENTS_DELAY 20  //ms
-#define LED_RW_SIG 16
-#define USB_SW_SEL 32
+#define USB_SW_SEL 32            // Switching pin number for connecting / disconnecting USB Mass Storage Drive
+#define HID_SW_SEL 11            // Switching pin number for connecting / disconnecting USB HID
+
+/* ----------- Operation Types -----------*/
+#define OPR_TYPE_RESERVED 0x00        // Reserved
+#define OPR_TYPE_KEYBOARD_WRITE 0x01  // Keyboard-related operation
+#define OPR_TYPE_MOUSE_WRITE 0x02     // Mouse-related operation
+#define OPR_TYPE_MOUSE_MOVE 0x03      // Mouse-move operation (Notes: When opr_type is OPR_TYPE_MOUSE_MOVE, opr_subtype is the X position value)
+#define OPR_TYPE_MOUSE_SCROLL 0x04    // Mouse scroll (Notes: when opr_type is OPR_TYPE_MOUSE_SCROLL, opr_subtype is up/down and payload is scroll tilt valie (max 127))
+#define OPR_TYPE_SWITCH_SET 0x05    // Switch/button operation
 
 
-/* Operation Types */
-#define OPR_TYPE_RESERVED 0x00           // Reserved
-#define OPR_TYPE_KEYBOARD_WRITE 0x01     // Keyboard-related operation
-#define OPR_TYPE_MOUSE_WRITE 0x02        // Mouse-related operation
-#define OPR_TYPE_MOUSE_MOVE 0x03         // Mouse-move operation (Notes: When opr_type is OPR_TYPE_MOUSE_MOVE, opr_subtype is the X position value)
-#define OPR_TYPE_MOUSE_SCROLL 0x04       //Mouse scroll (Notes: when opr_type is OPR_TYPE_MOUSE_SCROLL, opr_subtype is up/down and payload is scroll tilt valie (max 127))
-#define OPR_TYPE_SWITCH_WRITE 0x05       // Switch/button operation
-#define OPR_TYPE_LED_WRITE 0x06          // LED control operation
 #define OPR_TYPE_RESET_INSTR_COUNT 0xFE  // Reset instruction counter
 #define OPR_TYPE_RESET_INSTR_COUNT 0xFE  // Reset instruction counter
 #define OPR_TYPE_DATA_RESET 0xFF         //Reset opr data queue, if state of device is unknown, clear before use
 #define OPR_TYPE_DATA_RESET 0xFF         //Reset opr data queue, if state of device is unknown, clear before use
 
 
 /* Operation Sub-types */
 /* Operation Sub-types */
 #define SUBTYPE_RESERVED 0x00
 #define SUBTYPE_RESERVED 0x00
 
 
-/* Keyboard Subtypes */
+/* ----------- Keyboard Subtypes ----------- */
 #define SUBTYPE_KEYBOARD_ASCII_WRITE 0x01           // Write ASCII characters (32-127)
 #define SUBTYPE_KEYBOARD_ASCII_WRITE 0x01           // Write ASCII characters (32-127)
 #define SUBTYPE_KEYBOARD_ASCII_PRESS 0x02           // Press a key (ASCII 32-127)
 #define SUBTYPE_KEYBOARD_ASCII_PRESS 0x02           // Press a key (ASCII 32-127)
 #define SUBTYPE_KEYBOARD_ASCII_RELEASE 0x03         // Release a key (ASCII 32-127)
 #define SUBTYPE_KEYBOARD_ASCII_RELEASE 0x03         // Release a key (ASCII 32-127)
@@ -74,10 +74,10 @@
 #define PAYLOAD_NUMPAD_ENTER 0x0F
 #define PAYLOAD_NUMPAD_ENTER 0x0F
 #define PAYLOAD_NUMPAD_NUMLOCK 0x10
 #define PAYLOAD_NUMPAD_NUMLOCK 0x10
 
 
-/* Mouse Subtypes */
+/* ----------- Mouse Subtypes -----------*/
 #define SUBTYPE_MOUSE_CLICK 0x01
 #define SUBTYPE_MOUSE_CLICK 0x01
-#define SUBTYPE_MOUSE_PRESS 0x02  
-#define SUBTYPE_MOUSE_RELEASE 0x03  
+#define SUBTYPE_MOUSE_PRESS 0x02
+#define SUBTYPE_MOUSE_RELEASE 0x03
 #define SUBTYPE_MOUSE_SETPOS 0x04
 #define SUBTYPE_MOUSE_SETPOS 0x04
 #define SUBTYPE_MOUSE_RESET 0x05
 #define SUBTYPE_MOUSE_RESET 0x05
 
 
@@ -86,7 +86,11 @@
 #define PAYLOAD_MOUSE_BTN_RIGHT 0x02
 #define PAYLOAD_MOUSE_BTN_RIGHT 0x02
 #define PAYLOAD_MOUSE_BTN_MID 0x03
 #define PAYLOAD_MOUSE_BTN_MID 0x03
 
 
-/* Response Codes */
+/* ----------- Switches Subtypes -----------*/
+#define SUBTYPE_SWITCH_USBHID 0x01
+#define SUBTYPE_SWITCH_USBMASS 0x02
+
+/* ----------- Response Codes ----------- */
 #define resp_ok 0x00
 #define resp_ok 0x00
 #define resp_unknown_opr 0x01
 #define resp_unknown_opr 0x01
 #define resp_invalid_opr_type 0x02
 #define resp_invalid_opr_type 0x02

+ 10 - 2
usbkvm/usbkvm_fw/usbkvm_fw.ino

@@ -60,6 +60,7 @@ uint8_t keyboard_emulation(uint8_t, uint8_t);
 uint8_t mouse_emulation(uint8_t, uint8_t);
 uint8_t mouse_emulation(uint8_t, uint8_t);
 uint8_t mouse_move(uint8_t, uint8_t, uint8_t, uint8_t);
 uint8_t mouse_move(uint8_t, uint8_t, uint8_t, uint8_t);
 uint8_t mouse_wheel(uint8_t, uint8_t);
 uint8_t mouse_wheel(uint8_t, uint8_t);
+uint8_t usb_switch_emulation(uint8_t, uint8_t);
 
 
 /* KVM Operation Execution Catergory*/
 /* KVM Operation Execution Catergory*/
 uint8_t kvm_execute_opr() {
 uint8_t kvm_execute_opr() {
@@ -77,17 +78,24 @@ uint8_t kvm_execute_opr() {
       //mouse scroll
       //mouse scroll
       //for larger scroll tilt value, use the multipler
       //for larger scroll tilt value, use the multipler
       return mouse_wheel(opr_subtype, opr_payload);
       return mouse_wheel(opr_subtype, opr_payload);
+    case OPR_TYPE_SWITCH_SET:
+      //set USB signal bus switch state
+      return usb_switch_emulation(opr_subtype, opr_payload);
     default:
     default:
       return resp_unknown_opr;
       return resp_unknown_opr;
   }
   }
 }
 }
 
 
 void setup() {
 void setup() {
+  // Start CH340 UART COM
   Serial0_begin(115200);
   Serial0_begin(115200);
+  // Set both USB switch to LOW
   pinMode(USB_SW_SEL, OUTPUT);
   pinMode(USB_SW_SEL, OUTPUT);
-  pinMode(LED_RW_SIG, OUTPUT);
-  digitalWrite(LED_RW_SIG, HIGH);
+  pinMode(HID_SW_SEL, OUTPUT);
+  digitalWrite(HID_SW_SEL, LOW);
   digitalWrite(USB_SW_SEL, LOW);
   digitalWrite(USB_SW_SEL, LOW);
+  delay(100);
+  // Start USB HID emulation
   USBInit();
   USBInit();
 }
 }