usb_mass_storage.ino 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. digitalWrite(USB_MS_PWR, LOW);
  17. delay(USB_PWR_SW_PWR_DELAY);
  18. //Switch over the device
  19. digitalWrite(USB_MS_PWR, HIGH);
  20. delay(USB_PWR_SW_DATA_DELAY);
  21. digitalWrite(USB_MS_SW, HIGH);
  22. usb_ms_side = USB_MS_SIDE_KVM_HOST;
  23. }
  24. void switch_usbms_to_remote() {
  25. if (usb_ms_side == USB_MS_SIDE_REMOTE_PC) {
  26. //Already on Remote Side
  27. return;
  28. }
  29. #if ENABLE_DEBUG == 1
  30. USBSerial_println("[DEBUG] Switching USB Mass Storage node to remote computer side");
  31. #endif
  32. //Disconnect the power to USB
  33. digitalWrite(USB_MS_PWR, LOW);
  34. delay(USB_PWR_SW_PWR_DELAY);
  35. //Switch over the device
  36. digitalWrite(USB_MS_PWR, HIGH);
  37. delay(USB_PWR_SW_DATA_DELAY);
  38. digitalWrite(USB_MS_SW, LOW);
  39. usb_ms_side = USB_MS_SIDE_REMOTE_PC;
  40. }