usbd_pvt.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. #ifndef USBD_PVT_H_
  27. #define USBD_PVT_H_
  28. #include "osal/osal.h"
  29. #include "common/tusb_fifo.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. //--------------------------------------------------------------------+
  34. // USBD Endpoint API
  35. //--------------------------------------------------------------------+
  36. //bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
  37. void usbd_edpt_close(uint8_t rhport, uint8_t ep_addr);
  38. // Submit a usb transfer
  39. bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
  40. // Check if endpoint transferring is complete
  41. bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr);
  42. // Stall endpoint
  43. void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
  44. // Clear stalled endpoint
  45. void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
  46. // Check if endpoint is stalled
  47. bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
  48. static inline
  49. bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr)
  50. {
  51. return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr);
  52. }
  53. /*------------------------------------------------------------------*/
  54. /* Helper
  55. *------------------------------------------------------------------*/
  56. bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
  57. void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* USBD_PVT_H_ */