SCSI2SD_HID.hh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef SCSI2SD_HID_H
  18. #define SCSI2SD_HID_H
  19. #include "hidapi.h"
  20. #include <cstdint>
  21. #include <string>
  22. namespace SCSI2SD
  23. {
  24. class HID
  25. {
  26. public:
  27. static const uint16_t VENDOR_ID = 0x04B4; // Cypress
  28. static const uint16_t PRODUCT_ID = 0x1337; // SCSI2SD application firmware
  29. static const int CONFIG_INTERFACE = 0;
  30. static const int DEBUG_INTERFACE = 1;
  31. static const size_t HID_PACKET_SIZE = 64;
  32. static HID* Open();
  33. ~HID();
  34. uint16_t getFirmwareVersion() const { return myFirmwareVersion; }
  35. std::string getFirmwareVersionStr() const;
  36. uint32_t getSDCapacity() const { return mySDCapacity; }
  37. void enterBootloader();
  38. void readConfig(uint8_t* buffer, size_t len);
  39. void saveConfig(uint8_t* buffer, size_t len);
  40. private:
  41. HID(hid_device_info* hidInfo);
  42. void readDebugData();
  43. hid_device_info* myHidInfo;
  44. hid_device* myConfigHandle;
  45. hid_device* myDebugHandle;
  46. // Read-only data from the debug interface.
  47. uint16_t myFirmwareVersion;
  48. uint32_t mySDCapacity;
  49. };
  50. } // namespace
  51. #endif