mikroSDK Reference Manual
usbh_classdriver.h
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_CLASSDRIVER_H_
28#define _TUSB_USBH_CLASSDRIVER_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// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
39#ifndef CFG_TUH_LOG_LEVEL
40 #define CFG_TUH_LOG_LEVEL 2
41#endif
42
43#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
44
45enum {
46 USBH_EPSIZE_BULK_MAX = (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS)
47};
48
49//--------------------------------------------------------------------+
50// Class Driver API
51//--------------------------------------------------------------------+
52
53typedef struct {
54 #if CFG_TUSB_DEBUG >= 2
55 char const* name;
56 #endif
57
58 void (* const init )(void);
59 bool (* const open )(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
60 bool (* const set_config )(uint8_t dev_addr, uint8_t itf_num);
61 bool (* const xfer_cb )(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
62 void (* const close )(uint8_t dev_addr);
64
65// Call by class driver to tell USBH that it has complete the enumeration
66void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num);
67
68uint8_t usbh_get_rhport(uint8_t dev_addr);
69
70uint8_t* usbh_get_enum_buf(void);
71
72void usbh_int_set(bool enabled);
73
74//--------------------------------------------------------------------+
75// USBH Endpoint API
76//--------------------------------------------------------------------+
77
78// Submit a usb transfer with callback support, require CFG_TUH_API_EDPT_XFER
79bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
80 tuh_xfer_cb_t complete_cb, uintptr_t user_data);
81
82TU_ATTR_ALWAYS_INLINE
83static inline bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
84{
85 return usbh_edpt_xfer_with_callback(dev_addr, ep_addr, buffer, total_bytes, NULL, 0);
86}
87
88
89// Claim an endpoint before submitting a transfer.
90// If caller does not make any transfer, it must release endpoint for others.
91bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr);
92
93// Release claimed endpoint without submitting a transfer
94bool usbh_edpt_release(uint8_t dev_addr, uint8_t ep_addr);
95
96// Check if endpoint transferring is complete
97bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr);
98
99#ifdef __cplusplus
100 }
101#endif
102
103#endif
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
Definition usbh_classdriver.h:53