hidpacket.h 2.1 KB

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