|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2018, hathach for Adafruit |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#ifndef _TUSB_CONFIG_ESP32_H_ |
| 26 | +#define _TUSB_CONFIG_ESP32_H_ |
| 27 | + |
| 28 | +#ifdef __cplusplus |
| 29 | +extern "C" { |
| 30 | +#endif |
| 31 | + |
| 32 | +// ESP32 Arduino core already integrated tinyusb using lib arduino_tinyusb |
| 33 | +// https://github.com/espressif/esp32-arduino-lib-builder/tree/master/components/arduino_tinyusb |
| 34 | +// Although it is possible to use .c files in this library for linking instead |
| 35 | +// of lib arduino_tinyusb. However, include path of lib arduino_tinyusb is first |
| 36 | +// in order. Therefore, changes in this Adafruit TinyUSB library's header are |
| 37 | +// not picked up by its .c file. Due to the version difference between the 2 |
| 38 | +// libraries, this file is used to make it compatible with ESP32 Arduino core. |
| 39 | + |
| 40 | +// This file also contains additional configuration for EPS32 in addition to |
| 41 | +// tools/sdk/esp32xx/include/arduino_tinyusb/include/tusb_config.h |
| 42 | + |
| 43 | +//--------------------------------------------------------------------+ |
| 44 | +// ESP32 out-of-sync |
| 45 | +//--------------------------------------------------------------------+ |
| 46 | +#ifndef tu_static |
| 47 | +#define tu_static static |
| 48 | + |
| 49 | +#include <stddef.h> |
| 50 | +#include <string.h> |
| 51 | +static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { |
| 52 | + if (count > destsz) { |
| 53 | + return -1; |
| 54 | + } |
| 55 | + memset(dest, ch, count); |
| 56 | + return 0; |
| 57 | +} |
| 58 | +static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, |
| 59 | + size_t count) { |
| 60 | + if (count > destsz) { |
| 61 | + return -1; |
| 62 | + } |
| 63 | + memcpy(dest, src, count); |
| 64 | + return 0; |
| 65 | +} |
| 66 | +#endif |
| 67 | + |
| 68 | +#ifndef CFG_TUD_MEM_SECTION |
| 69 | +#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION |
| 70 | +#endif |
| 71 | + |
| 72 | +#ifndef CFG_TUD_LOG_LEVEL |
| 73 | +#define CFG_TUD_LOG_LEVEL 2 |
| 74 | +#endif |
| 75 | + |
| 76 | +#if 0 |
| 77 | +//-------------------------------------------------------------------- |
| 78 | +// COMMON CONFIGURATION |
| 79 | +//-------------------------------------------------------------------- |
| 80 | +#define CFG_TUSB_MCU OPT_MCU_NRF5X |
| 81 | + |
| 82 | +#define CFG_TUSB_OS OPT_OS_FREERTOS |
| 83 | +#define CFG_TUSB_MEM_SECTION |
| 84 | +#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4))) |
| 85 | + |
| 86 | +#ifndef CFG_TUSB_DEBUG |
| 87 | +#define CFG_TUSB_DEBUG 0 |
| 88 | +#endif |
| 89 | + |
| 90 | +// For selectively disable device log (when > CFG_TUSB_DEBUG) |
| 91 | +// #define CFG_TUD_LOG_LEVEL 3 |
| 92 | + |
| 93 | +#ifdef USE_TINYUSB |
| 94 | +// Enable device stack |
| 95 | +#define CFG_TUD_ENABLED 1 |
| 96 | + |
| 97 | +// Enable host stack with MAX3421E (host shield) |
| 98 | +#define CFG_TUH_ENABLED 1 |
| 99 | +#define CFG_TUH_MAX3421 1 |
| 100 | + |
| 101 | +#else |
| 102 | +#define CFG_TUD_ENABLED 0 |
| 103 | +#define CFG_TUH_ENABLED 0 |
| 104 | +#endif |
| 105 | + |
| 106 | +//-------------------------------------------------------------------- |
| 107 | +// DEVICE CONFIGURATION |
| 108 | +//-------------------------------------------------------------------- |
| 109 | + |
| 110 | +//-------------------------------------------------------------------- |
| 111 | +// Host Configuration |
| 112 | +//-------------------------------------------------------------------- |
| 113 | + |
| 114 | +// Size of buffer to hold descriptors and other data used for enumeration |
| 115 | +#define CFG_TUH_ENUMERATION_BUFSIZE 256 |
| 116 | + |
| 117 | +// Number of hub devices |
| 118 | +#define CFG_TUH_HUB 1 |
| 119 | + |
| 120 | +// max device support (excluding hub device): 1 hub typically has 4 ports |
| 121 | +#define CFG_TUH_DEVICE_MAX (3 * CFG_TUH_HUB + 1) |
| 122 | + |
| 123 | +// Enable tuh_edpt_xfer() API |
| 124 | +// #define CFG_TUH_API_EDPT_XFER 1 |
| 125 | + |
| 126 | +// Number of mass storage |
| 127 | +#define CFG_TUH_MSC 1 |
| 128 | + |
| 129 | +// Number of HIDs |
| 130 | +// typical keyboard + mouse device can have 3,4 HID interfaces |
| 131 | +#define CFG_TUH_HID (3 * CFG_TUH_DEVICE_MAX) |
| 132 | + |
| 133 | +// Number of CDC interfaces |
| 134 | +// FTDI and CP210x are not part of CDC class, only to re-use CDC driver API |
| 135 | +#define CFG_TUH_CDC 1 |
| 136 | +#define CFG_TUH_CDC_FTDI 1 |
| 137 | +#define CFG_TUH_CDC_CP210X 1 |
| 138 | + |
| 139 | +// RX & TX fifo size |
| 140 | +#define CFG_TUH_CDC_RX_BUFSIZE 64 |
| 141 | +#define CFG_TUH_CDC_TX_BUFSIZE 64 |
| 142 | + |
| 143 | +// Set Line Control state on enumeration/mounted: |
| 144 | +// DTR ( bit 0), RTS (bit 1) |
| 145 | +#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03 |
| 146 | + |
| 147 | +// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t |
| 148 | +// bit rate = 115200, 1 stop bit, no parity, 8 bit data width |
| 149 | +// This need Pico-PIO-USB at least 0.5.1 |
| 150 | +#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \ |
| 151 | + { 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 } |
| 152 | + |
| 153 | +#endif |
| 154 | + |
| 155 | +#ifdef __cplusplus |
| 156 | +} |
| 157 | +#endif |
| 158 | + |
| 159 | +#endif |
0 commit comments