pof_usb.h 2.6 KB

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