pof_usb.h 2.6 KB

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