tinyusb.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /**
  17. * @brief Configuration structure of the TinyUSB core
  18. *
  19. * USB specification mandates self-powered devices to monitor USB VBUS to detect connection/disconnection events.
  20. * If you want to use this feature, connected VBUS to any free GPIO through a voltage divider or voltage comparator.
  21. * The voltage divider output should be (0.75 * Vdd) if VBUS is 4.4V (lowest valid voltage at device port).
  22. * The comparator thresholds should be set with hysteresis: 4.35V (falling edge) and 4.75V (raising edge).
  23. */
  24. typedef struct {
  25. union {
  26. 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 */
  27. const tusb_desc_device_t *descriptor __attribute__((deprecated)); /*!< Alias to `device_descriptor` for backward compatibility */
  28. };
  29. const char **string_descriptor; /*!< Pointer to an array of string descriptors */
  30. bool external_phy; /*!< Should USB use an external PHY */
  31. 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 */
  32. bool self_powered; /*!< This is a self-powered USB device. USB VBUS must be monitored. */
  33. int vbus_monitor_io; /*!< GPIO for VBUS monitoring. Ignored if not self_powered. */
  34. } tinyusb_config_t;
  35. /**
  36. * @brief This is an all-in-one helper function, including:
  37. * 1. USB device driver initialization
  38. * 2. Descriptors preparation
  39. * 3. TinyUSB stack initialization
  40. * 4. Creates and start a task to handle usb events
  41. *
  42. * @note Don't change Custom descriptor, but if it has to be done,
  43. * Suggest to define as follows in order to match the Interface Association Descriptor (IAD):
  44. * bDeviceClass = TUSB_CLASS_MISC,
  45. * bDeviceSubClass = MISC_SUBCLASS_COMMON,
  46. *
  47. * @param config tinyusb stack specific configuration
  48. * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument
  49. * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error
  50. * @retval ESP_OK Install driver and tinyusb stack successfully
  51. */
  52. esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
  53. // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
  54. #ifdef __cplusplus
  55. }
  56. #endif