Open FFBoard
Open source force feedback firmware
usbh_pvt.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021, 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_USBH_PVT_H_
28#define _TUSB_USBH_PVT_H_
29
30#include "osal/osal.h"
31#include "common/tusb_fifo.h"
32#include "common/tusb_private.h"
33
34#ifdef __cplusplus
35 extern "C" {
36#endif
37
38#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
39#define TU_LOG_MEM_USBH(...) TU_LOG_MEM(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
40#define TU_LOG_BUF_USBH(...) TU_LOG_BUF(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
41#define TU_LOG_INT_USBH(...) TU_LOG_INT(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
42#define TU_LOG_HEX_USBH(...) TU_LOG_HEX(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
43
44enum {
45 USBH_EPSIZE_BULK_MAX = (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS)
46};
47
48//--------------------------------------------------------------------+
49// Class Driver API
50//--------------------------------------------------------------------+
51
52typedef struct {
53 char const* name;
54 bool (* const init )(void);
55 bool (* const deinit )(void);
56 bool (* const open )(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
57 bool (* const set_config )(uint8_t dev_addr, uint8_t itf_num);
58 bool (* const xfer_cb )(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
59 void (* const close )(uint8_t dev_addr);
61
62// Invoked when initializing host stack to get additional class drivers.
63// Can be implemented by application to extend/overwrite class driver support.
64// Note: The drivers array must be accessible at all time when stack is active
65usbh_class_driver_t const* usbh_app_driver_get_cb(uint8_t* driver_count) TU_ATTR_WEAK;
66
67// Call by class driver to tell USBH that it has complete the enumeration
68void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num);
69
70uint8_t usbh_get_rhport(uint8_t dev_addr);
71
72uint8_t* usbh_get_enum_buf(void);
73
74void usbh_int_set(bool enabled);
75
76void usbh_defer_func(osal_task_func_t func, void *param, bool in_isr);
77
78//--------------------------------------------------------------------+
79// USBH Endpoint API
80//--------------------------------------------------------------------+
81
82// Submit a usb transfer with callback support, require CFG_TUH_API_EDPT_XFER
83bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
85
86TU_ATTR_ALWAYS_INLINE
87static inline bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) {
88 return usbh_edpt_xfer_with_callback(dev_addr, ep_addr, buffer, total_bytes, NULL, 0);
89}
90
91// Claim an endpoint before submitting a transfer.
92// If caller does not make any transfer, it must release endpoint for others.
93bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr);
94
95// Release claimed endpoint without submitting a transfer
96bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr);
97
98// Check if endpoint transferring is complete
99bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr);
100
101#ifdef __cplusplus
102 }
103#endif
104
105#endif
static bool in_isr
uint16_t total_bytes
Definition: dcd_nuc505.c:113
uint8_t dev_addr
Definition: dcd_pic32mz.c:81
uint8_t const * buffer
Definition: midi_device.h:100
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
char const * name
Definition: usbh_pvt.h:53
@ TUSB_EPSIZE_BULK_HS
Definition: tusb_types.h:74
@ TUSB_EPSIZE_BULK_FS
Definition: tusb_types.h:73
xfer_result_t
Definition: tusb_types.h:236
uintptr_t user_data
Definition: usbh.c:262
tuh_xfer_cb_t complete_cb
Definition: usbh.c:261
void(* tuh_xfer_cb_t)(tuh_xfer_t *xfer)
Definition: usbh.h:44
bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
Definition: usbh.c:877
void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
Definition: usbh.c:1717
usbh_class_driver_t const * usbh_app_driver_get_cb(uint8_t *driver_count) TU_ATTR_WEAK
bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr)
Definition: usbh.c:861
void usbh_defer_func(osal_task_func_t func, void *param, bool in_isr)
Definition: usbh.c:832
uint8_t * usbh_get_enum_buf(void)
Definition: usbh.c:819
void usbh_int_set(bool enabled)
Definition: usbh.c:823
bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr)
Definition: usbh.c:846
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
Definition: usbh.c:935
static TU_ATTR_ALWAYS_INLINE bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
Definition: usbh_pvt.h:87
uint8_t usbh_get_rhport(uint8_t dev_addr)
Definition: usbh.c:814