class_common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Define to prevent recursive inclusion -------------------------------------*/
  2. #ifndef __USB_COMMON_CLASS_H
  3. #define __USB_COMMON_CLASS_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* Includes ------------------------------------------------------------------*/
  8. #include "usbd_ioreq.h"
  9. #include "usb/usb_hooks.h"
  10. #include "usb/usb_config.h"
  11. #include "core/config.h"
  12. #include "drivers/usb/class/common/class_common.h"
  13. // RECREATE_CONTROL_TRANSFER_OBJ
  14. // Re-create transfer object for each transaction (=1), or keep old object (=0)
  15. #define RECREATE_CONTROL_TRANSFER_OBJ 1
  16. // DATAIN_INITIATESEND_REQUIRED
  17. // Set to 1 if the hardware does not support NAK interrupt for IN endpoints,
  18. // so to send data it is required to initiate the first packet send by application
  19. #define DATAIN_INITIATESEND_REQUIRED 1
  20. /*---------------------------------------------------------------------*/
  21. /* VENDOR definitions */
  22. /*---------------------------------------------------------------------*/
  23. typedef struct _USBD_COMMON_Itf
  24. {
  25. fUsbInit_t fUsbInit;
  26. fUsbDeInit_t fUsbDeInit;
  27. fUsbSetupRx_t fUsbSetup; // optional
  28. fUsbCtlEpRx_t fUsbCtlEpRx; // optional
  29. fUsbCtlEpTx_t fUsbCtlEpTx; // optional
  30. fUsbBusReset_t fResetEvent; // optional, OK
  31. fUsbSuspendEvent_t fSuspendEvent; // optional, Not impleneded in STM32 driver (see HAL_PCD_SuspendCallback)
  32. fUsbSetIface_t fSetIface; // optional, OK (SET_INTERFACE request)
  33. fUsbClrIface_t fClrIface; // optional, OK (CLR_INTERFACE request)
  34. fUsbGetIface_t fGetIface; // optional, OK (GET_INTERFACE request)
  35. fUsbDataRx_t fDataRxHandler; // optional ( endpoints I/O )
  36. fUsbDataTx_t fDataTxHandler; // optional ( endpoints I/O )
  37. fUsbDataErr_t fDataErrHandler; // optional ( endpoints I/O )
  38. }USBD_COMMON_ItfTypeDef;
  39. // USBD_COMMON_EP0_RxReady
  40. // This function is called when a packet via CONTROL protocol had been received from host
  41. // This function continues the transmitting
  42. uint8_t USBD_COMMON_EP0_RxReady (USBD_HandleTypeDef *pdev, sUSBTransfer_t * rx, size_t * pnBytesRollback );
  43. // USBD_COMMON_EP0_TxSent()
  44. // This function is called when at least one packet via CONTROL protocol had been sent to the host
  45. // This function continues the transmitting
  46. uint8_t USBD_COMMON_EP0_TxSent (USBD_HandleTypeDef *pdev, sUSBTransfer_t * tx, size_t * pnBytesRollback );
  47. // USBD_COMMON_Setup_DataProcess()
  48. // Handler for specific vendor or class requests
  49. // @pdev, @pUserIface, @req and @transf MUST BE NON-NULL!
  50. // Do not call if @req->wLength is zero
  51. uint8_t USBD_COMMON_Setup_DataProcess( USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req, sUSBTransfer_t * transf );
  52. // USBD_COMMON_DataInProcess
  53. // Process DataIN events for Bulk and Interrupt endpoints
  54. uint8_t USBD_COMMON_DataInProcess( USBD_HandleTypeDef *pdev, uint8_t epnum, sUSBTransfer_t * transf );
  55. // USBD_USBTMC_DataIn_ZeroSend
  56. // Queue zero packet in EP IN
  57. uint8_t USBD_COMMON_DataIn_ZeroSend( USBD_HandleTypeDef *pdev, uint8_t epnum );
  58. // USBD_COMMON_DataIn_BeginSend
  59. // Initiates the first packet sending
  60. // @bTxAlreadyPrepared - if the TX-transfer is already prepared to transmission, do not reset transfer, do not call TX-handler
  61. uint8_t USBD_COMMON_DataIn_BeginSend( USBD_HandleTypeDef *pdev, uint8_t epnum, sUSBTransfer_t * transf, bool bTxAlreadyPrepared );
  62. // USBD_COMMON_DataOutProcess
  63. // Process DataOUT events for Bulk and Interrupt endpoints
  64. uint8_t USBD_COMMON_DataOutProcess( USBD_HandleTypeDef *pdev, uint8_t epnum, sUSBTransfer_t * transf, bool ShortPacketReceived );
  65. // USBD_COMMON_DataOutBegin
  66. // Prepare the EP for next OUT (receive) transaction
  67. uint8_t USBD_COMMON_DataOutBegin( USBD_HandleTypeDef *pdev, uint8_t epnum, sUSBTransfer_t * transf );
  68. #if USBD_CONSTSUBCLASS_IFACE
  69. uint8_t USBD_COMMON_RegisterInterface (USBD_HandleTypeDef *pdev,
  70. const USBD_COMMON_ItfTypeDef *fops);
  71. #else
  72. uint8_t USBD_COMMON_RegisterInterface (USBD_HandleTypeDef *pdev,
  73. USBD_COMMON_ItfTypeDef *fops);
  74. #endif
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* __USB_COMMON_CLASS_H */