SCSI2SD_Bootloader.hh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_Bootloader_H
  18. #define SCSI2SD_Bootloader_H
  19. extern "C"
  20. {
  21. #include "cybtldr_api.h"
  22. #include "cybtldr_api2.h"
  23. #include "hidapi.h"
  24. }
  25. #if __cplusplus >= 201103L
  26. #include <cstdint>
  27. #else
  28. #include <stdint.h>
  29. #endif
  30. #include <string>
  31. namespace SCSI2SD
  32. {
  33. class Bootloader
  34. {
  35. public:
  36. static const uint16_t VENDOR_ID = 0x04B4; // Cypress
  37. static const uint16_t PRODUCT_ID = 0xB71D; // Default PSoC3/5LP Bootloader
  38. static const size_t HID_PACKET_SIZE = 64;
  39. struct OperationScope
  40. {
  41. public:
  42. OperationScope();
  43. ~OperationScope();
  44. };
  45. static Bootloader* Open();
  46. ~Bootloader();
  47. struct HWInfo
  48. {
  49. std::string desc;
  50. std::string version;
  51. std::string firmwareName;
  52. };
  53. HWInfo getHWInfo() const;
  54. // USB HID data
  55. std::string getDevicePath() const;
  56. std::wstring getManufacturer() const;
  57. std::wstring getProductString() const;
  58. bool isCorrectFirmware(const std::string& path) const;
  59. // progress function accepts flash array ID and row Number
  60. void load(const std::string& path, void (*progress)(uint8_t, uint16_t));
  61. // Check the connection to the bootloader is valid.
  62. bool ping() const;
  63. CyBtldr_CommunicationsData getCyBtldr();
  64. private:
  65. Bootloader(hid_device_info* hidInfo);
  66. hid_device_info* myHidInfo;
  67. hid_device* myBootloaderHandle;
  68. };
  69. } // namespace
  70. #endif