tinyusb.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdbool.h>
  8. #include "esp_err.h"
  9. #include "tusb.h"
  10. #include "tusb_option.h"
  11. #include "tusb_config.h"
  12. #include "tinyusb_types.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /* tinyusb uses buffers with type of uint8_t[] but in our driver we are reading them as a 32-bit word */
  17. #if (CFG_TUD_ENDPOINT0_SIZE < 4)
  18. # define CFG_TUD_ENDPOINT0_SIZE 4
  19. # warning "CFG_TUD_ENDPOINT0_SIZE was too low and was set to 4"
  20. #endif
  21. #if TUSB_OPT_DEVICE_ENABLED
  22. # if CFG_TUD_HID
  23. # if (CFG_TUD_HID_BUFSIZE < 4)
  24. # define CFG_TUD_HID_BUFSIZE 4
  25. # warning "CFG_TUD_HID_BUFSIZE was too low and was set to 4"
  26. # endif
  27. # endif
  28. # if CFG_TUD_CDC
  29. # if (CFG_TUD_CDC_EP_BUFSIZE < 4)
  30. # define CFG_TUD_CDC_EP_BUFSIZE 4
  31. # warning "CFG_TUD_CDC_EP_BUFSIZE was too low and was set to 4"
  32. # endif
  33. # endif
  34. # if CFG_TUD_MSC
  35. # if (CFG_TUD_MSC_BUFSIZE < 4)
  36. # define CFG_TUD_MSC_BUFSIZE 4
  37. # warning "CFG_TUD_MSC_BUFSIZE was too low and was set to 4"
  38. # endif
  39. # endif
  40. # if CFG_TUD_MIDI
  41. # if (CFG_TUD_MIDI_EPSIZE < 4)
  42. # define CFG_TUD_MIDI_EPSIZE 4
  43. # warning "CFG_TUD_MIDI_EPSIZE was too low and was set to 4"
  44. # endif
  45. # endif
  46. # if CFG_TUD_CUSTOM_CLASS
  47. # warning "Please check that the buffer is more then 4 bytes"
  48. # endif
  49. #endif
  50. /**
  51. * @brief Configuration structure of the tinyUSB core
  52. */
  53. typedef struct {
  54. tusb_desc_device_t *descriptor; /*!< Pointer to a device descriptor */
  55. const char **string_descriptor; /*!< Pointer to an array of string descriptors */
  56. bool external_phy; /*!< Should USB use an external PHY */
  57. } tinyusb_config_t;
  58. /**
  59. * @brief This is an all-in-one helper function, including:
  60. * 1. USB device driver initialization
  61. * 2. Descriptors preparation
  62. * 3. TinyUSB stack initialization
  63. * 4. Creates and start a task to handle usb events
  64. *
  65. * @note Don't change Custom descriptor, but if it has to be done,
  66. * Suggest to define as follows in order to match the Interface Association Descriptor (IAD):
  67. * bDeviceClass = TUSB_CLASS_MISC,
  68. * bDeviceSubClass = MISC_SUBCLASS_COMMON,
  69. *
  70. * @param config tinyusb stack specific configuration
  71. * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument
  72. * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error
  73. * @retval ESP_OK Install driver and tinyusb stack successfully
  74. */
  75. esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
  76. // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
  77. #ifdef __cplusplus
  78. }
  79. #endif