Kestrel Interface
Loading...
Searching...
No Matches
tusb_config.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Ha Thach (tinyusb.org),
3 * SPDX-FileContributor: 2020-2025 Espressif Systems (Shanghai) CO LTD
4 * SPDX-License-Identifier: MIT
5 *
6 * Copyright (c) 2019 Ha Thach (tinyusb.org),
7 * Additions Copyright (c) 2020, Espressif Systems (Shanghai) PTE LTD
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 *
27 */
28
29#pragma once
30
31#include "tusb_option.h"
32#include "sdkconfig.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#ifndef CONFIG_TINYUSB_CDC_ENABLED
39# define CONFIG_TINYUSB_CDC_ENABLED 0
40#endif
41
42#ifndef CONFIG_TINYUSB_CDC_COUNT
43# define CONFIG_TINYUSB_CDC_COUNT 0
44#endif
45
46#ifndef CONFIG_TINYUSB_MSC_ENABLED
47# define CONFIG_TINYUSB_MSC_ENABLED 1
48#endif
49
50#ifndef CONFIG_TINYUSB_HID_COUNT
51# define CONFIG_TINYUSB_HID_COUNT 0
52#endif
53
54#ifndef CONFIG_TINYUSB_MIDI_COUNT
55# define CONFIG_TINYUSB_MIDI_COUNT 0
56#endif
57
58#ifndef CONFIG_TINYUSB_VENDOR_COUNT
59# define CONFIG_TINYUSB_VENDOR_COUNT 0
60#endif
61
62#ifndef CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
63# define CONFIG_TINYUSB_NET_MODE_ECM_RNDIS 0
64#endif
65
66#ifndef CONFIG_TINYUSB_NET_MODE_NCM
67# define CONFIG_TINYUSB_NET_MODE_NCM 0
68#endif
69
70#ifndef CONFIG_TINYUSB_DFU_MODE_DFU
71# define CONFIG_TINYUSB_DFU_MODE_DFU 0
72#endif
73
74#ifndef CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME
75# define CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME 0
76#endif
77
78#ifndef CONFIG_TINYUSB_BTH_ENABLED
79# define CONFIG_TINYUSB_BTH_ENABLED 0
80# define CONFIG_TINYUSB_BTH_ISO_ALT_COUNT 0
81#endif
82
83#ifndef CONFIG_TINYUSB_DEBUG_LEVEL
84# define CONFIG_TINYUSB_DEBUG_LEVEL 0
85#endif
86
87#define CFG_TUD_ENABLED 1 // TinyUSB Device enabled
88
89#if (CONFIG_IDF_TARGET_ESP32P4)
90#define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED
91#else
92#define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED
93#endif
94
95// ------------------------------------------------------------------------
96// DCD DWC2 Mode
97// ------------------------------------------------------------------------
98#define CFG_TUD_DWC2_SLAVE_ENABLE 1 // Enable Slave/IRQ by default
99
100// ------------------------------------------------------------------------
101// DMA & Cache
102// ------------------------------------------------------------------------
103#ifdef CONFIG_TINYUSB_MODE_DMA
104// DMA Mode has a priority over Slave/IRQ mode and will be used if hardware supports it
105#define CFG_TUD_DWC2_DMA_ENABLE 1 // Enable DMA
106
107#if CONFIG_CACHE_L1_CACHE_LINE_SIZE
108// To enable the dcd_dcache clean/invalidate/clean_invalidate calls
109# define CFG_TUD_MEM_DCACHE_ENABLE 1
110#define CFG_TUD_MEM_DCACHE_LINE_SIZE CONFIG_CACHE_L1_CACHE_LINE_SIZE
111// NOTE: starting with esp-idf v5.3 there is specific attribute present: DRAM_DMA_ALIGNED_ATTR
112# define CFG_TUSB_MEM_SECTION __attribute__((aligned(CONFIG_CACHE_L1_CACHE_LINE_SIZE))) DRAM_ATTR
113#else
114# define CFG_TUD_MEM_CACHE_ENABLE 0
115# define CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) DRAM_ATTR
116#endif // CONFIG_CACHE_L1_CACHE_LINE_SIZE
117#endif // CONFIG_TINYUSB_MODE_DMA
118
119#define CFG_TUSB_OS OPT_OS_FREERTOS
120
121/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
122 * Tinyusb use follows macros to declare transferring memory so that they can be put
123 * into those specific section.
124 * e.g
125 * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
126 * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
127 */
128#ifndef CFG_TUSB_MEM_SECTION
129# define CFG_TUSB_MEM_SECTION
130#endif
131
132#ifndef CFG_TUSB_MEM_ALIGN
133# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
134#endif
135
136#ifndef CFG_TUD_ENDPOINT0_SIZE
137#define CFG_TUD_ENDPOINT0_SIZE 64
138#endif
139
140// Debug Level
141#define CFG_TUSB_DEBUG CONFIG_TINYUSB_DEBUG_LEVEL
142#define CFG_TUSB_DEBUG_PRINTF esp_rom_printf // TinyUSB can print logs from ISR, so we must use esp_rom_printf()
143
144// CDC FIFO size of TX and RX
145#define CFG_TUD_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE
146#define CFG_TUD_CDC_TX_BUFSIZE CONFIG_TINYUSB_CDC_TX_BUFSIZE
147#define CFG_TUD_CDC_EP_BUFSIZE CONFIG_TINYUSB_CDC_EP_BUFSIZE
148
149// MSC Buffer size of Device Mass storage
150#define CFG_TUD_MSC_BUFSIZE CONFIG_TINYUSB_MSC_BUFSIZE
151
152// MIDI macros
153#define CFG_TUD_MIDI_EP_BUFSIZE 64
154#define CFG_TUD_MIDI_EPSIZE CFG_TUD_MIDI_EP_BUFSIZE
155#define CFG_TUD_MIDI_RX_BUFSIZE 64
156#define CFG_TUD_MIDI_TX_BUFSIZE 64
157
158// Vendor FIFO size of TX and RX
159#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
160#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
161
162// DFU macros
163#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE
164
165// Number of BTH ISO alternatives
166#define CFG_TUD_BTH_ISO_ALT_COUNT CONFIG_TINYUSB_BTH_ISO_ALT_COUNT
167
168// Enabled device class driver
169#define CFG_TUD_CDC CONFIG_TINYUSB_CDC_COUNT
170#define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED
171#define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT
172#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT
173#define CFG_TUD_VENDOR CONFIG_TINYUSB_VENDOR_COUNT
174#define CFG_TUD_ECM_RNDIS CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
175#define CFG_TUD_NCM CONFIG_TINYUSB_NET_MODE_NCM
176#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_MODE_DFU
177#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME
178#define CFG_TUD_BTH CONFIG_TINYUSB_BTH_ENABLED
179
180// NCM NET Mode NTB buffers configuration
181#define CFG_TUD_NCM_OUT_NTB_N CONFIG_TINYUSB_NCM_OUT_NTB_BUFFS_COUNT
182#define CFG_TUD_NCM_IN_NTB_N CONFIG_TINYUSB_NCM_IN_NTB_BUFFS_COUNT
183#define CFG_TUD_NCM_OUT_NTB_MAX_SIZE CONFIG_TINYUSB_NCM_OUT_NTB_BUFF_MAX_SIZE
184#define CFG_TUD_NCM_IN_NTB_MAX_SIZE CONFIG_TINYUSB_NCM_IN_NTB_BUFF_MAX_SIZE
185
186#ifdef __cplusplus
187}
188#endif