usb_switch.ino 931 B

123456789101112131415161718192021222324252627282930313233
  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. }
  18. return resp_invalid_key_value;
  19. case SUBTYPE_SWITCH_USBMASS:
  20. if (value == 0x00) {
  21. digitalWrite(USB_SW_SEL, LOW);
  22. return resp_ok;
  23. } else if (value == 0x01) {
  24. digitalWrite(USB_SW_SEL, HIGH);
  25. return resp_ok;
  26. }
  27. return resp_invalid_key_value;
  28. default:
  29. return resp_invalid_opr_type;
  30. }
  31. }