cdc.h 3.6 KB

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