usb_switch.ino 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. USB Switch
  3. This script handle commands that switch the USB mass storage device
  4. to the host or slave side
  5. */
  6. #include "usbkvm_fw.h"
  7. //Entry point for switching USB bus signals, value only support 0x00 (A) and 0x01 (B)
  8. uint8_t usb_switch_emulation(uint8_t subtype, uint8_t value) {
  9. switch (subtype) {
  10. case SUBTYPE_SWITCH_USBHID:
  11. if (value == 0x00) {
  12. digitalWrite(HID_SW_SEL, LOW);
  13. return resp_ok;
  14. } else if (value == 0x01) {
  15. digitalWrite(HID_SW_SEL, HIGH);
  16. return resp_ok;
  17. } else if (value == 0x02){
  18. //Software reset with HID Switch reconnections
  19. digitalWrite(HID_SW_SEL, HIGH);
  20. delay(100);
  21. SoftwareReset();
  22. //After reset the switch is automatically pull LOW
  23. return resp_ok; //Should be not reachable
  24. }
  25. return resp_invalid_key_value;
  26. case SUBTYPE_SWITCH_USBMASS:
  27. if (value == 0x00) {
  28. digitalWrite(USB_SW_SEL, LOW);
  29. return resp_ok;
  30. } else if (value == 0x01) {
  31. digitalWrite(USB_SW_SEL, HIGH);
  32. return resp_ok;
  33. }
  34. return resp_invalid_key_value;
  35. default:
  36. return resp_invalid_opr_type;
  37. }
  38. }