tinyusb.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stdbool.h>
  16. #include "tusb.h"
  17. #include "tusb_option.h"
  18. #include "tusb_config.h"
  19. #include "tinyusb_types.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* tinyusb uses buffers with type of uint8_t[] but in our driver we are reading them as a 32-bit word */
  24. #if (CFG_TUD_ENDPOINT0_SIZE < 4)
  25. # define CFG_TUD_ENDPOINT0_SIZE 4
  26. # warning "CFG_TUD_ENDPOINT0_SIZE was too low and was set to 4"
  27. #endif
  28. #if TUSB_OPT_DEVICE_ENABLED
  29. # if CFG_TUD_HID
  30. # if (CFG_TUD_HID_BUFSIZE < 4)
  31. # define CFG_TUD_HID_BUFSIZE 4
  32. # warning "CFG_TUD_HID_BUFSIZE was too low and was set to 4"
  33. # endif
  34. # endif
  35. # if CFG_TUD_CDC
  36. # if (CFG_TUD_CDC_EP_BUFSIZE < 4)
  37. # define CFG_TUD_CDC_EP_BUFSIZE 4
  38. # warning "CFG_TUD_CDC_EP_BUFSIZE was too low and was set to 4"
  39. # endif
  40. # endif
  41. # if CFG_TUD_MSC
  42. # if (CFG_TUD_MSC_BUFSIZE < 4)
  43. # define CFG_TUD_MSC_BUFSIZE 4
  44. # warning "CFG_TUD_MSC_BUFSIZE was too low and was set to 4"
  45. # endif
  46. # endif
  47. # if CFG_TUD_MIDI
  48. # if (CFG_TUD_MIDI_EPSIZE < 4)
  49. # define CFG_TUD_MIDI_EPSIZE 4
  50. # warning "CFG_TUD_MIDI_EPSIZE was too low and was set to 4"
  51. # endif
  52. # endif
  53. # if CFG_TUD_CUSTOM_CLASS
  54. # warning "Please check that the buffer is more then 4 bytes"
  55. # endif
  56. #endif
  57. /**
  58. * @brief Configuration structure of the tinyUSB core
  59. */
  60. typedef struct {
  61. tusb_desc_device_t *descriptor; /*!< Pointer to a device descriptor */
  62. const char **string_descriptor; /*!< Pointer to an array of string descriptors */
  63. bool external_phy; /*!< Should USB use an external PHY */
  64. } tinyusb_config_t;
  65. /**
  66. * @brief This is an all-in-one helper function, including:
  67. * 1. USB device driver initialization
  68. * 2. Descriptors preparation
  69. * 3. TinyUSB stack initialization
  70. * 4. Creates and start a task to handle usb events
  71. *
  72. * @note Don't change Custom descriptor, but if it has to be done,
  73. * Suggest to define as follows in order to match the Interface Association Descriptor (IAD):
  74. * bDeviceClass = TUSB_CLASS_MISC,
  75. * bDeviceSubClass = MISC_SUBCLASS_COMMON,
  76. *
  77. * @param config tinyusb stack specific configuration
  78. * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument
  79. * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error
  80. * @retval ESP_OK Install driver and tinyusb stack successfully
  81. */
  82. esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
  83. // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
  84. #ifdef __cplusplus
  85. }
  86. #endif