pof_usb.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include <furi_hal.h>
  3. #include <furi_hal_version.h>
  4. #include <furi_hal_usb.h>
  5. #include <furi_hal_usb_hid.h>
  6. #include "usb.h"
  7. #include "usb_hid.h"
  8. #include "virtual_portal.h"
  9. #define HID_REPORT_TYPE_INPUT 1
  10. #define HID_REPORT_TYPE_OUTPUT 2
  11. #define HID_REPORT_TYPE_FEATURE 3
  12. #define POF_USB_EP_IN_SIZE (64UL)
  13. #define POF_USB_EP_OUT_SIZE (64UL)
  14. #define POF_USB_RX_MAX_SIZE (POF_USB_EP_OUT_SIZE)
  15. #define POF_USB_TX_MAX_SIZE (POF_USB_EP_IN_SIZE)
  16. typedef struct PoFUsb PoFUsb;
  17. PoFUsb* pof_usb_start(VirtualPortal* virtual_portal);
  18. void pof_usb_stop(PoFUsb* pof);
  19. PoFUsb* pof_usb_start_xbox360(VirtualPortal* virtual_portal);
  20. void pof_usb_stop_xbox360(PoFUsb* pof);
  21. /*descriptor type*/
  22. typedef enum {
  23. PoFDescriptorTypeDevice = 0x01,
  24. PoFDescriptorTypeConfig = 0x02,
  25. PoFDescriptorTypeString = 0x03,
  26. PoFDescriptorTypeInterface = 0x04,
  27. PoFDescriptorTypeEndpoint = 0x05,
  28. } PoFDescriptorType;
  29. /*endpoint direction*/
  30. typedef enum {
  31. PoFEndpointIn = 0x80,
  32. PoFEndpointOut = 0x00,
  33. } PoFEndpointDirection;
  34. /*endpoint type*/
  35. typedef enum {
  36. PoFEndpointTypeCtrl = 0x00,
  37. PoFEndpointTypeIso = 0x01,
  38. PoFEndpointTypeBulk = 0x02,
  39. PoFEndpointTypeIntr = 0x03,
  40. } PoFEndpointType;
  41. /*control request type*/
  42. typedef enum {
  43. PoFControlTypeStandard = (0 << 5),
  44. PoFControlTypeClass = (1 << 5),
  45. PoFControlTypeVendor = (2 << 5),
  46. PoFControlTypeReserved = (3 << 5),
  47. } PoFControlType;
  48. /*control request recipient*/
  49. typedef enum {
  50. PoFControlRecipientDevice = 0,
  51. PoFControlRecipientInterface = 1,
  52. PoFControlRecipientEndpoint = 2,
  53. PoFControlRecipientOther = 3,
  54. } PoFControlRecipient;
  55. /*control request direction*/
  56. typedef enum {
  57. PoFControlOut = 0x00,
  58. PoFControlIn = 0x80,
  59. } PoFControlDirection;
  60. /*endpoint address mask*/
  61. typedef enum {
  62. PoFEndpointAddrMask = 0x0f,
  63. PoFEndpointDirMask = 0x80,
  64. PoFEndpointTransferTypeMask = 0x03,
  65. PoFCtrlDirMask = 0x80,
  66. } PoFEndpointMask;
  67. /* USB control requests */
  68. typedef enum {
  69. PoFControlRequestsOut = (PoFControlTypeVendor | PoFControlRecipientDevice | PoFControlOut),
  70. PoFControlRequestsIn = (PoFControlTypeVendor | PoFControlRecipientDevice | PoFControlIn),
  71. } PoFControlRequests;
  72. struct PoFUsb {
  73. FuriHalUsbInterface usb;
  74. FuriHalUsbInterface* usb_prev;
  75. FuriThread* thread;
  76. usbd_device* dev;
  77. VirtualPortal* virtual_portal;
  78. uint8_t data_recvest[8];
  79. uint16_t data_recvest_len;
  80. bool tx_complete;
  81. bool tx_immediate;
  82. uint8_t dataAvailable;
  83. uint8_t data[POF_USB_RX_MAX_SIZE];
  84. uint8_t tx_data[POF_USB_TX_MAX_SIZE];
  85. };