1 // Copyright 2020 Espressif Systems (Shanghai) PTE 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 #include <stdbool.h> 18 #include "tusb.h" 19 #include "tusb_option.h" 20 #include "tusb_config.h" 21 #include "tinyusb_types.h" 22 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 29 /* tinyusb uses buffers with type of uint8_t[] but in our driver we are reading them as a 32-bit word */ 30 #if (CFG_TUD_ENDPOINT0_SIZE < 4) 31 # define CFG_TUD_ENDPOINT0_SIZE 4 32 # warning "CFG_TUD_ENDPOINT0_SIZE was too low and was set to 4" 33 #endif 34 35 #if TUSB_OPT_DEVICE_ENABLED 36 37 # if CFG_TUD_HID 38 # if (CFG_TUD_HID_BUFSIZE < 4) 39 # define CFG_TUD_HID_BUFSIZE 4 40 # warning "CFG_TUD_HID_BUFSIZE was too low and was set to 4" 41 # endif 42 # endif 43 44 # if CFG_TUD_CDC 45 # if (CFG_TUD_CDC_EP_BUFSIZE < 4) 46 # define CFG_TUD_CDC_EP_BUFSIZE 4 47 # warning "CFG_TUD_CDC_EP_BUFSIZE was too low and was set to 4" 48 # endif 49 # endif 50 51 # if CFG_TUD_MSC 52 # if (CFG_TUD_MSC_BUFSIZE < 4) 53 # define CFG_TUD_MSC_BUFSIZE 4 54 # warning "CFG_TUD_MSC_BUFSIZE was too low and was set to 4" 55 # endif 56 # endif 57 58 # if CFG_TUD_MIDI 59 # if (CFG_TUD_MIDI_EPSIZE < 4) 60 # define CFG_TUD_MIDI_EPSIZE 4 61 # warning "CFG_TUD_MIDI_EPSIZE was too low and was set to 4" 62 # endif 63 # endif 64 65 # if CFG_TUD_CUSTOM_CLASS 66 # warning "Please check that the buffer is more then 4 bytes" 67 # endif 68 #endif 69 70 /** 71 * @brief Configuration structure of the tinyUSB core 72 */ 73 typedef struct { 74 tusb_desc_device_t *descriptor; /*!< Pointer to a device descriptor */ 75 const char **string_descriptor; /*!< Pointer to an array of string descriptors */ 76 bool external_phy; /*!< Should USB use an external PHY */ 77 } tinyusb_config_t; 78 79 /** 80 * @brief This is an all-in-one helper function, including: 81 * 1. USB device driver initialization 82 * 2. Descriptors preparation 83 * 3. TinyUSB stack initialization 84 * 4. Creates and start a task to handle usb events 85 * 86 * @note Don't change Custom descriptor, but if it has to be done, 87 * Suggest to define as follows in order to match the Interface Association Descriptor (IAD): 88 * bDeviceClass = TUSB_CLASS_MISC, 89 * bDeviceSubClass = MISC_SUBCLASS_COMMON, 90 * 91 * @param config tinyusb stack specific configuration 92 * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument 93 * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error 94 * @retval ESP_OK Install driver and tinyusb stack successfully 95 */ 96 esp_err_t tinyusb_driver_install(const tinyusb_config_t *config); 97 98 // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474) 99 100 #ifdef __cplusplus 101 } 102 #endif 103