Port XEBEC controller support from v5 firmware
[SCSI2SD-V6.git] / include / hidpacket.h
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 // Library for sending packet data over a USB HID connection.
19 // Supports reassembly of packets larger than the HID packet,
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define USBHID_LEN 64
26
27 // Maximum packet payload length. Must be large enough to support a SD sector
28 // + sector number
29 #define HIDPACKET_MAX_LEN 520
30
31 #include <stddef.h>
32 #include <stdint.h>
33
34 // The first byte of each HID packet contains the hid chunk number.
35 // High-bit indicates a final chunk.
36 // The second byte of each HID packet contains the payload length.
37
38 // Call this with HID bytes received. len <= USBHID_LEN
39 void hidPacket_recv(const uint8_t* bytes, size_t len);
40
41 // Returns the received packet contents, or NULL if a complete packet isn't
42 // available.
43 const uint8_t* hidPacket_getPacket(size_t* len);
44
45 // Returns the received packet contents, or NULL if a complete packet isn't
46 // available.
47 const uint8_t* hidPacket_peekPacket(size_t* len);
48
49 // Call this with packet data to send. len <= USBHID_LEN
50 // Overwrites any packet currently being sent.
51 void hidPacket_send(const uint8_t* bytes, size_t len);
52
53 // Returns USBHID_LEN bytes to send in the next HID packet, or
54 // NULL if there's nothing to send.
55 const uint8_t* hidPacket_getHIDBytes(uint8_t* hidBuffer);
56
57 #ifdef __cplusplus
58 } // extern "C"
59 #endif
60