cdc.h 3.0 KB

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