Open FFBoard
Open source force feedback firmware
tusb.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
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 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_H_
28#define _TUSB_H_
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34//--------------------------------------------------------------------+
35// INCLUDE
36//--------------------------------------------------------------------+
37#include "common/tusb_common.h"
38#include "osal/osal.h"
39#include "common/tusb_fifo.h"
40
41//------------- TypeC -------------//
42#if CFG_TUC_ENABLED
43 #include "typec/usbc.h"
44#endif
45
46//------------- HOST -------------//
47#if CFG_TUH_ENABLED
48 #include "host/usbh.h"
49
50 #if CFG_TUH_HID
51 #include "class/hid/hid_host.h"
52 #endif
53
54 #if CFG_TUH_MSC
55 #include "class/msc/msc_host.h"
56 #endif
57
58 #if CFG_TUH_CDC
59 #include "class/cdc/cdc_host.h"
60 #endif
61
62 #if CFG_TUH_VENDOR
64 #endif
65#else
66 #ifndef tuh_int_handler
67 #define tuh_int_handler(...)
68 #endif
69#endif
70
71//------------- DEVICE -------------//
72#if CFG_TUD_ENABLED
73 #include "device/usbd.h"
74
75 #if CFG_TUD_HID
76 #include "class/hid/hid_device.h"
77 #endif
78
79 #if CFG_TUD_CDC
80 #include "class/cdc/cdc_device.h"
81 #endif
82
83 #if CFG_TUD_MSC
84 #include "class/msc/msc_device.h"
85 #endif
86
87 #if CFG_TUD_AUDIO
89 #endif
90
91 #if CFG_TUD_VIDEO
93 #endif
94
95 #if CFG_TUD_MIDI
97 #endif
98
99 #if CFG_TUD_VENDOR
101 #endif
102
103 #if CFG_TUD_USBTMC
105 #endif
106
107 #if CFG_TUD_DFU_RUNTIME
109 #endif
110
111 #if CFG_TUD_DFU
112 #include "class/dfu/dfu_device.h"
113 #endif
114
115 #if CFG_TUD_ECM_RNDIS || CFG_TUD_NCM
116 #include "class/net/net_device.h"
117 #endif
118
119 #if CFG_TUD_BTH
120 #include "class/bth/bth_device.h"
121 #endif
122#else
123 #ifndef tud_int_handler
124 #define tud_int_handler(...)
125 #endif
126#endif
127
128
129//--------------------------------------------------------------------+
130// User API
131//--------------------------------------------------------------------+
132#if CFG_TUH_ENABLED || CFG_TUD_ENABLED
133
134// Internal helper for backward compatible with tusb_init(void)
135bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init);
136
137// Initialize roothub port with device/host role
138// Note: when using with RTOS, this should be called after scheduler/kernel is started.
139// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
140// Note2: defined as macro for backward compatible with tusb_init(void), can be changed to function in the future.
141#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
142 #define _tusb_init_arg0() tusb_rhport_init(0, NULL)
143#else
144 #define _tusb_init_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined")
145#endif
146
147#define _tusb_init_arg1(_rhport) _tusb_init_arg0()
148#define _tusb_init_arg2(_rhport, _rh_init) tusb_rhport_init(_rhport, _rh_init)
149#define tusb_init(...) TU_FUNC_OPTIONAL_ARG(_tusb_init, __VA_ARGS__)
150
151// Check if stack is initialized
152bool tusb_inited(void);
153
154// Called to handle usb interrupt/event. tusb_init(rhport, role) must be called before
155void tusb_int_handler(uint8_t rhport, bool in_isr);
156
157// TODO
158// bool tusb_teardown(void);
159
160#else
161
162#define tusb_init(...) (false)
163#define tusb_int_handler(...) do {}while(0)
164#define tusb_inited() (false)
165
166#endif
167
168//--------------------------------------------------------------------+
169// API Implemented by user
170//--------------------------------------------------------------------+
171
172// Get current milliseconds, required by some port/configuration without RTOS
173uint32_t tusb_time_millis_api(void);
174
175// Delay in milliseconds, use tusb_time_millis_api() by default. required by some port/configuration with no RTOS
176void tusb_time_delay_ms_api(uint32_t ms);
177
178#ifdef __cplusplus
179 }
180#endif
181
182#endif /* _TUSB_H_ */
static bool in_isr
bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t *rh_init)
Definition: tusb.c:61
uint32_t tusb_time_millis_api(void)
void tusb_time_delay_ms_api(uint32_t ms)
Definition: tusb.c:48
void tusb_int_handler(uint8_t rhport, bool in_isr)
Definition: tusb.c:122
bool tusb_inited(void)
Definition: tusb.c:108