mikroSDK Reference Manual
tcd.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2023 Ha Thach (thach@tinyusb.org) for Adafruit Industries
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_TCD_H_
28#define _TUSB_TCD_H_
29
30#include "common/tusb_common.h"
31#include "pd_types.h"
32
33#include "osal/osal.h"
34#include "common/tusb_fifo.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40//--------------------------------------------------------------------+
41//
42//--------------------------------------------------------------------+
43
44enum {
45 TCD_EVENT_INVALID = 0,
46 TCD_EVENT_CC_CHANGED,
47 TCD_EVENT_RX_COMPLETE,
48 TCD_EVENT_TX_COMPLETE,
49};
50
51typedef struct TU_ATTR_PACKED {
52 uint8_t rhport;
53 uint8_t event_id;
54
55 union {
56 struct {
57 uint8_t cc_state[2];
58 } cc_changed;
59
60 struct TU_ATTR_PACKED {
61 uint16_t result : 2;
62 uint16_t xferred_bytes : 14;
63 } xfer_complete;
64 };
65
67
68//--------------------------------------------------------------------+
69//
70//--------------------------------------------------------------------+
71
72// Initialize controller
73bool tcd_init(uint8_t rhport, uint32_t port_type);
74
75// Enable interrupt
76void tcd_int_enable (uint8_t rhport);
77
78// Disable interrupt
79void tcd_int_disable(uint8_t rhport);
80
81// Interrupt Handler
82void tcd_int_handler(uint8_t rhport);
83
84//--------------------------------------------------------------------+
85//
86//--------------------------------------------------------------------+
87
88bool tcd_msg_receive(uint8_t rhport, uint8_t* buffer, uint16_t total_bytes);
89bool tcd_msg_send(uint8_t rhport, uint8_t const* buffer, uint16_t total_bytes);
90
91//--------------------------------------------------------------------+
92// Event API (implemented by stack)
93// Called by TCD to notify stack
94//--------------------------------------------------------------------+
95
96extern void tcd_event_handler(tcd_event_t const * event, bool in_isr);
97
98TU_ATTR_ALWAYS_INLINE static inline
99void tcd_event_cc_changed(uint8_t rhport, uint8_t cc1, uint8_t cc2, bool in_isr) {
100 tcd_event_t event = {
101 .rhport = rhport,
102 .event_id = TCD_EVENT_CC_CHANGED,
103 .cc_changed = {
104 .cc_state = {cc1, cc2 }
105 }
106 };
107
108 tcd_event_handler(&event, in_isr);
109}
110
111TU_ATTR_ALWAYS_INLINE static inline
112void tcd_event_rx_complete(uint8_t rhport, uint16_t xferred_bytes, uint8_t result, bool in_isr) {
113 tcd_event_t event = {
114 .rhport = rhport,
115 .event_id = TCD_EVENT_RX_COMPLETE,
116 .xfer_complete = {
117 .xferred_bytes = xferred_bytes,
118 .result = result
119 }
120 };
121
122 tcd_event_handler(&event, in_isr);
123}
124
125TU_ATTR_ALWAYS_INLINE static inline
126void tcd_event_tx_complete(uint8_t rhport, uint16_t xferred_bytes, uint8_t result, bool in_isr) {
127 tcd_event_t event = {
128 .rhport = rhport,
129 .event_id = TCD_EVENT_TX_COMPLETE,
130 .xfer_complete = {
131 .xferred_bytes = xferred_bytes,
132 .result = result
133 }
134 };
135
136 tcd_event_handler(&event, in_isr);
137}
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647