cdc.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdint.h>
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/semphr.h"
  13. #include "freertos/timers.h"
  14. #include "tusb.h"
  15. #include "tinyusb_types.h"
  16. /* CDC classification
  17. ********************************************************************* */
  18. typedef enum {
  19. TINYUSB_CDC_DATA = 0x00,
  20. } cdc_data_sublcass_type_t; // CDC120 specification
  21. /* Note:other classification is represented in the file components\tinyusb\tinyusb\src\class\cdc\cdc.h */
  22. /*********************************************************************** CDC classification*/
  23. /* Structs
  24. ********************************************************************* */
  25. typedef struct {
  26. tinyusb_usbdev_t usb_dev; /*!< USB device to set up */
  27. tusb_class_code_t cdc_class; /*!< CDC device class : Communications or Data device */
  28. union {
  29. cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: AMC, ECM, etc. */
  30. cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/
  31. } cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */
  32. } tinyusb_config_cdc_t; /*!< Main configuration structure of a CDC device */
  33. typedef struct {
  34. tinyusb_usbdev_t usb_dev; /*!< USB device used for the instance */
  35. tusb_class_code_t type;
  36. union {
  37. cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: AMC, ECM, etc. */
  38. cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/
  39. } cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */
  40. void *subclass_obj; /*!< Dynamically allocated subclass specific object */
  41. } esp_tusb_cdc_t;
  42. /*********************************************************************** Structs*/
  43. /* Functions
  44. ********************************************************************* */
  45. /**
  46. * @brief Initializing CDC basic object
  47. * @param itf - number of a CDC object
  48. * @param cfg - CDC configuration structure
  49. *
  50. * @return esp_err_t ESP_OK or ESP_FAIL
  51. */
  52. esp_err_t tinyusb_cdc_init(int itf, const tinyusb_config_cdc_t *cfg);
  53. /**
  54. * @brief De-initializing CDC. Clean its objects
  55. * @param itf - number of a CDC object
  56. * @return esp_err_t ESP_OK, ESP_ERR_INVALID_ARG, ESP_ERR_INVALID_STATE
  57. *
  58. */
  59. esp_err_t tinyusb_cdc_deinit(int itf);
  60. /**
  61. * @brief Return interface of a CDC device
  62. *
  63. * @param itf_num
  64. * @return esp_tusb_cdc_t* pointer to the interface or (NULL) on error
  65. */
  66. esp_tusb_cdc_t *tinyusb_cdc_get_intf(int itf_num);
  67. /*********************************************************************** Functions*/
  68. #ifdef __cplusplus
  69. }
  70. #endif