tinyusb.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. union {
  55. const tusb_desc_device_t *device_descriptor; /*!< Pointer to a device descriptor. If set to NULL, the TinyUSB device will use a default device descriptor whose values are set in Kconfig */
  56. const tusb_desc_device_t *descriptor __attribute__((deprecated)); /*!< Alias to `device_descriptor` for backward compatibility */
  57. };
  58. const char **string_descriptor; /*!< Pointer to an array of string descriptors */
  59. bool external_phy; /*!< Should USB use an external PHY */
  60. const uint8_t *configuration_descriptor; /*!< Pointer to a configuration descriptor. If set to NULL, TinyUSB device will use a default configuration descriptor whose values are set in Kconfig */
  61. } tinyusb_config_t;
  62. /**
  63. * @brief This is an all-in-one helper function, including:
  64. * 1. USB device driver initialization
  65. * 2. Descriptors preparation
  66. * 3. TinyUSB stack initialization
  67. * 4. Creates and start a task to handle usb events
  68. *
  69. * @note Don't change Custom descriptor, but if it has to be done,
  70. * Suggest to define as follows in order to match the Interface Association Descriptor (IAD):
  71. * bDeviceClass = TUSB_CLASS_MISC,
  72. * bDeviceSubClass = MISC_SUBCLASS_COMMON,
  73. *
  74. * @param config tinyusb stack specific configuration
  75. * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument
  76. * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error
  77. * @retval ESP_OK Install driver and tinyusb stack successfully
  78. */
  79. esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
  80. // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
  81. #ifdef __cplusplus
  82. }
  83. #endif