mikroSDK Reference Manual
usbd_pvt.h
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#ifndef USBD_PVT_H_
27#define USBD_PVT_H_
28
29#include "osal/osal.h"
30#include "common/tusb_fifo.h"
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36// Level where CFG_TUSB_DEBUG must be at least for USBD is logged
37#ifndef CFG_TUD_LOG_LEVEL
38#define CFG_TUD_LOG_LEVEL 2
39#endif
40
41#define TU_LOG_USBD(...) TU_LOG(CFG_TUD_LOG_LEVEL, __VA_ARGS__)
42
43//--------------------------------------------------------------------+
44// Class Driver API
45//--------------------------------------------------------------------+
46
47typedef struct
48{
49 #if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
50 char const* name;
51 #endif
52
53 void (* init ) (void);
54 void (* reset ) (uint8_t rhport);
55 uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
56 bool (* control_xfer_cb ) (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
57 bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
58 void (* sof ) (uint8_t rhport, uint32_t frame_count); // optional
60
61// Invoked when initializing device stack to get additional class drivers.
62// Can optionally implemented by application to extend/overwrite class driver support.
63// Note: The drivers array must be accessible at all time when stack is active
64usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) TU_ATTR_WEAK;
65
66typedef bool (*usbd_control_xfer_cb_t)(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
67
68void usbd_int_set(bool enabled);
69
70//--------------------------------------------------------------------+
71// USBD Endpoint API
72// Note: rhport should be 0 since device stack only support 1 rhport for now
73//--------------------------------------------------------------------+
74
75// Open an endpoint
76bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep);
77
78// Close an endpoint
79void usbd_edpt_close(uint8_t rhport, uint8_t ep_addr);
80
81// Submit a usb transfer
82bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
83
84// Submit a usb ISO transfer by use of a FIFO (ring buffer) - all bytes in FIFO get transmitted
85bool usbd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes);
86
87// Claim an endpoint before submitting a transfer.
88// If caller does not make any transfer, it must release endpoint for others.
89bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr);
90
91// Release claimed endpoint without submitting a transfer
92bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr);
93
94// Check if endpoint is busy transferring
95bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr);
96
97// Stall endpoint
98void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
99
100// Clear stalled endpoint
101void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
102
103// Check if endpoint is stalled
104bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
105
106// Allocate packet buffer used by ISO endpoints
107bool usbd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size);
108
109// Configure and enable an ISO endpoint according to descriptor
110bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
111
112// Check if endpoint is ready (not busy and not stalled)
113TU_ATTR_ALWAYS_INLINE static inline
114bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr)
115{
116 return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr);
117}
118
119// Enable SOF interrupt
120void usbd_sof_enable(uint8_t rhport, bool en);
121
122/*------------------------------------------------------------------*/
123/* Helper
124 *------------------------------------------------------------------*/
125
126bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
127void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
128
129
130#ifdef __cplusplus
131 }
132#endif
133
134#endif /* USBD_PVT_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
Definition tusb_fifo.h:108
Definition usbd_pvt.h:48