usbd_transc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*!
  2. \file usbd_transc.h
  3. \brief USBD transaction
  4. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2023, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #ifndef __USB_TRANSC_H
  30. #define __USB_TRANSC_H
  31. #include "usbd_core.h"
  32. /*!
  33. \brief USB transaction configure
  34. \param[in] transc: pointer to USB device transaction instance
  35. \param[in] buf: transfer data buffer
  36. \param[in] len: transfer data length
  37. \param[in] count: transfer data counter
  38. \param[out] none
  39. \retval none
  40. */
  41. __STATIC_INLINE void usb_transc_config (usb_transc *transc, uint8_t *buf, uint16_t len, uint16_t count)
  42. {
  43. transc->xfer_buf = buf;
  44. transc->xfer_len = len;
  45. transc->xfer_count = count;
  46. }
  47. /*!
  48. \brief USB stalled transaction
  49. \param[in] udev: pointer to USB device instance
  50. \param[out] none
  51. \retval none
  52. */
  53. __STATIC_INLINE void usb_stall_transc (usb_dev *udev)
  54. {
  55. usbd_ep_stall(udev, 0x0U);
  56. }
  57. /*!
  58. \brief USB control transaction status in stage
  59. \param[in] udev: pointer to USB device instance
  60. \param[out] none
  61. \retval none
  62. */
  63. __STATIC_INLINE void usb_ctl_status_in (usb_dev *udev)
  64. {
  65. udev->control.ctl_state = USBD_CTL_STATUS_IN;
  66. udev->drv_handler->ep_write(udev->transc_in[0].xfer_buf, 0U, 0U);
  67. }
  68. /*!
  69. \brief USB control transaction data in stage
  70. \param[in] udev: pointer to USB device instance
  71. \param[out] none
  72. \retval none
  73. */
  74. __STATIC_INLINE void usb_ctl_data_in (usb_dev *udev)
  75. {
  76. udev->control.ctl_state = USBD_CTL_DATA_IN;
  77. usbd_ep_send(udev, 0U, udev->transc_in[0].xfer_buf, udev->transc_in[0].xfer_len);
  78. }
  79. /*!
  80. \brief USB control transaction data out & status out stage
  81. \param[in] udev: pointer to USB device instance
  82. \param[out] none
  83. \retval none
  84. */
  85. __STATIC_INLINE void usb_ctl_data_out (usb_dev *udev)
  86. {
  87. udev->control.ctl_state = USBD_CTL_DATA_OUT;
  88. udev->drv_handler->ep_rx_enable(udev, 0U);
  89. }
  90. /*!
  91. \brief USB control transaction status OUT stage
  92. \param[in] udev: pointer to USB device instance
  93. \param[out] none
  94. \retval none
  95. */
  96. static inline void usb_ctl_status_out (usb_dev *udev)
  97. {
  98. udev->control.ctl_state = USBD_CTL_STATUS_OUT;
  99. udev->drv_handler->ep_rx_enable(udev, 0U);
  100. }
  101. /*!
  102. \brief USB send 0 length data packet
  103. \param[in] udev: pointer to USB device instance
  104. \param[out] none
  105. \retval none
  106. */
  107. __STATIC_INLINE void usb_0len_packet_send (usb_dev *udev)
  108. {
  109. udev->drv_handler->ep_write(udev->transc_in[0].xfer_buf, 0U, 0U);
  110. }
  111. /* function declarations */
  112. /* process USB SETUP transaction */
  113. void _usb_setup_transc (usb_dev *udev, uint8_t ep_num);
  114. /* process USB OUT transaction */
  115. void _usb_out0_transc (usb_dev *udev, uint8_t ep_num);
  116. /* process USB IN transaction */
  117. void _usb_in0_transc (usb_dev *udev, uint8_t ep_num);
  118. #endif /* __USB_TRANSC_H */