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