Small compatibility improvements, and added scsi2sd-monitor test program
[SCSI2SD-V6.git] / software / scsi2sd-util / SCSI2SD_HID.hh
CommitLineData
5e0f1e33
MM
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
18#ifndef SCSI2SD_HID_H
19#define SCSI2SD_HID_H
20
21#include "hidapi.h"
22
70a3b594 23#if __cplusplus >= 201103L
5e0f1e33 24#include <cstdint>
70a3b594
MM
25#else
26#include <stdint.h>
27#endif
28
5e0f1e33 29#include <string>
75f825e6 30#include <vector>
5e0f1e33
MM
31
32namespace SCSI2SD
33{
34
35class HID
36{
37public:
38 static const uint16_t VENDOR_ID = 0x04B4; // Cypress
39 static const uint16_t PRODUCT_ID = 0x1337; // SCSI2SD application firmware
40
41 static const int CONFIG_INTERFACE = 0;
42 static const int DEBUG_INTERFACE = 1;
43
44 static const size_t HID_PACKET_SIZE = 64;
45
5446dc86
MM
46 // HID intervals for 4.0.3 firmware: <= 128ms
47 // > 4.0.3 = 32ms.
48 static const size_t HID_TIMEOUT_MS = 256; // 2x HID Interval.
49
50
5e0f1e33
MM
51 static HID* Open();
52
53 ~HID();
54
55 uint16_t getFirmwareVersion() const { return myFirmwareVersion; }
56 std::string getFirmwareVersionStr() const;
57 uint32_t getSDCapacity() const { return mySDCapacity; }
5446dc86
MM
58 std::vector<uint8_t> getSD_CSD();
59 std::vector<uint8_t> getSD_CID();
5e0f1e33 60
9ad7cc15
MM
61 bool scsiSelfTest();
62
5e0f1e33
MM
63 void enterBootloader();
64
75f825e6
MM
65 void readFlashRow(int array, int row, std::vector<uint8_t>& out);
66 void writeFlashRow(int array, int row, const std::vector<uint8_t>& in);
67 bool ping();
5446dc86
MM
68
69 bool readSCSIDebugInfo(std::vector<uint8_t>& buf);
70
5e0f1e33
MM
71private:
72 HID(hid_device_info* hidInfo);
75f825e6 73 void destroy();
5e0f1e33 74 void readDebugData();
75f825e6
MM
75 void readHID(uint8_t* buffer, size_t len);
76 void sendHIDPacket(
5446dc86
MM
77 const std::vector<uint8_t>& cmd,
78 std::vector<uint8_t>& out,
79 size_t responseLength
75f825e6 80 );
5e0f1e33
MM
81
82 hid_device_info* myHidInfo;
83 hid_device* myConfigHandle;
84 hid_device* myDebugHandle;
85
86 // Read-only data from the debug interface.
87 uint16_t myFirmwareVersion;
88 uint32_t mySDCapacity;
89};
90
91} // namespace
92
93#endif