usb_mass_storage.ino 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. usb_mass_storage.ino
  3. author: tobychui
  4. This file include functions that handles
  5. USB mass storage switching
  6. */
  7. void switch_usbms_to_kvm() {
  8. if (usb_ms_side == USB_MS_SIDE_KVM_HOST) {
  9. //Already on the KVM side
  10. return;
  11. }
  12. #if ENABLE_DEBUG == 1
  13. USBSerial_println("[DEBUG] Switching USB Mass Storage node to KVM host side");
  14. #endif
  15. //Disconnect the power to USB
  16. #ifndef COMPATIBLE_VERSION_FIVE_PCB
  17. digitalWrite(USB_MS_PWR, LOW);
  18. delay(USB_PWR_SW_PWR_DELAY);
  19. #endif
  20. //Switch over the device
  21. digitalWrite(USB_MS_PWR, HIGH);
  22. delay(USB_PWR_SW_DATA_DELAY);
  23. digitalWrite(USB_MS_SW, HIGH);
  24. usb_ms_side = USB_MS_SIDE_KVM_HOST;
  25. }
  26. void switch_usbms_to_remote() {
  27. if (usb_ms_side == USB_MS_SIDE_REMOTE_PC) {
  28. //Already on Remote Side
  29. return;
  30. }
  31. #if ENABLE_DEBUG == 1
  32. USBSerial_println("[DEBUG] Switching USB Mass Storage node to remote computer side");
  33. #endif
  34. //Disconnect the power to USB
  35. #ifndef COMPATIBLE_VERSION_FIVE_PCB
  36. digitalWrite(USB_MS_PWR, LOW);
  37. delay(USB_PWR_SW_PWR_DELAY);
  38. #endif
  39. //Switch over the device
  40. digitalWrite(USB_MS_PWR, HIGH);
  41. delay(USB_PWR_SW_DATA_DELAY);
  42. digitalWrite(USB_MS_SW, LOW);
  43. usb_ms_side = USB_MS_SIDE_REMOTE_PC;
  44. }