usbd_core.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*!
  2. \file usbd_core.h
  3. \brief USB device mode core driver header file
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. */
  8. /*
  9. Copyright (c) 2018, GigaDevice Semiconductor Inc.
  10. All rights reserved.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef USBD_CORE_H
  33. #define USBD_CORE_H
  34. #include "usbd_conf.h"
  35. #include "usb_core.h"
  36. #include "usbd_std.h"
  37. /* constants definitions */
  38. /* device status */
  39. #define USB_STATUS_DEFAULT 1U /* default status */
  40. #define USB_STATUS_ADDRESSED 2U /* addressed status */
  41. #define USB_STATUS_CONFIGURED 3U /* configured status */
  42. #define USB_STATUS_SUSPENDED 4U /* suspended status */
  43. /* function declarations */
  44. /* initailizes the USB device-mode handler stack */
  45. void usbd_init (usb_core_handle_struct *pudev, usb_core_id_enum core_id);
  46. /* endpoint initialization */
  47. void usbd_ep_init (usb_core_handle_struct *pudev, const usb_descriptor_endpoint_struct *ep_desc);
  48. /* endpoint deinitialize */
  49. void usbd_ep_deinit (usb_core_handle_struct *pudev, uint8_t ep_addr);
  50. /* endpoint prepare to receive data */
  51. void usbd_ep_rx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len);
  52. /* endpoint prepare to transmit data */
  53. void usbd_ep_tx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len);
  54. /* transmit data on the control channel */
  55. usbd_status_enum usbd_ctltx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len);
  56. /* receive data on the control channel */
  57. usbd_status_enum usbd_ctlrx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len);
  58. /* transmit status on the control channel */
  59. usbd_status_enum usbd_ctlstatus_tx (usb_core_handle_struct *pudev);
  60. /* receive status on the control channel */
  61. usbd_status_enum usbd_ctlstatus_rx (usb_core_handle_struct *pudev);
  62. /* set an endpoint to stall status */
  63. void usbd_ep_stall (usb_core_handle_struct *pudev, uint8_t ep_addr);
  64. /* clear endpoint stalled status */
  65. void usbd_ep_clear_stall (usb_core_handle_struct *pudev, uint8_t ep_addr);
  66. /* flushes the fifos */
  67. void usbd_ep_fifo_flush (usb_core_handle_struct *pudev, uint8_t ep_addr);
  68. /* get the received data length */
  69. uint16_t usbd_rxcount_get (usb_core_handle_struct *pudev, uint8_t ep_num);
  70. #endif /* USBD_CORE_H */