Open FFBoard
Open source force feedback firmware
tcd.h
Go to the documentation of this file.
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 {
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];
59
60 struct TU_ATTR_PACKED {
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
static bool in_isr
uint16_t total_bytes
Definition: dcd_nuc505.c:113
uint8_t const * buffer
Definition: midi_device.h:100
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint8_t cc_state[2]
Definition: tcd.h:57
uint16_t result
Definition: tcd.h:61
struct TU_ATTR_PACKED::@670::TU_ATTR_PACKED xfer_complete
volatile uint16_t
Definition: hcd_rusb2.c:58
struct TU_ATTR_PACKED::@670::@672 cc_changed
uint8_t rhport
Definition: tcd.h:52
uint8_t event_id
Definition: tcd.h:53
uint16_t xferred_bytes
Definition: tcd.h:62
void tcd_int_handler(uint8_t rhport)
Definition: typec_stm32.c:238
void tcd_int_disable(uint8_t rhport)
Definition: typec_stm32.c:208
static TU_ATTR_ALWAYS_INLINE void tcd_event_tx_complete(uint8_t rhport, uint16_t xferred_bytes, uint8_t result, bool in_isr)
Definition: tcd.h:126
static TU_ATTR_ALWAYS_INLINE void tcd_event_cc_changed(uint8_t rhport, uint8_t cc1, uint8_t cc2, bool in_isr)
Definition: tcd.h:99
struct TU_ATTR_PACKED tcd_event_t
bool tcd_init(uint8_t rhport, uint32_t port_type)
Definition: typec_stm32.c:167
bool tcd_msg_receive(uint8_t rhport, uint8_t *buffer, uint16_t total_bytes)
Definition: typec_stm32.c:213
void tcd_int_enable(uint8_t rhport)
Definition: typec_stm32.c:202
static TU_ATTR_ALWAYS_INLINE void tcd_event_rx_complete(uint8_t rhport, uint16_t xferred_bytes, uint8_t result, bool in_isr)
Definition: tcd.h:112
@ TCD_EVENT_CC_CHANGED
Definition: tcd.h:46
@ TCD_EVENT_TX_COMPLETE
Definition: tcd.h:48
@ TCD_EVENT_RX_COMPLETE
Definition: tcd.h:47
@ TCD_EVENT_INVALID
Definition: tcd.h:45
void tcd_event_handler(tcd_event_t const *event, bool in_isr)
Definition: usbc.c:185
bool tcd_msg_send(uint8_t rhport, uint8_t const *buffer, uint16_t total_bytes)
Definition: typec_stm32.c:219