|
36 | 36 | #include "host/usbh.h"
|
37 | 37 | #include "host/usbh_pvt.h"
|
38 | 38 |
|
39 |
| -//--------------------------------------------------------------------+ |
40 |
| -// ESP32 out-of-sync |
41 |
| -//--------------------------------------------------------------------+ |
42 |
| -#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO) |
43 |
| -#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 5) |
44 |
| -typedef struct { |
45 |
| - uint8_t daddr; |
46 |
| - tusb_desc_interface_t desc; |
47 |
| -} tuh_itf_info_t; |
48 |
| - |
49 |
| -typedef struct { |
50 |
| - bool is_host; // host or device most |
51 |
| - union { |
52 |
| - uint8_t daddr; |
53 |
| - uint8_t rhport; |
54 |
| - uint8_t hwid; |
55 |
| - }; |
56 |
| - uint8_t ep_addr; |
57 |
| - uint8_t ep_speed; |
58 |
| - |
59 |
| - uint16_t ep_packetsize; |
60 |
| - uint16_t ep_bufsize; |
61 |
| - |
62 |
| - // TODO xfer_fifo can skip this buffer |
63 |
| - uint8_t* ep_buf; |
64 |
| - |
65 |
| - tu_fifo_t ff; |
66 |
| - |
67 |
| - // mutex: read if ep rx, write if e tx |
68 |
| - OSAL_MUTEX_DEF(ff_mutex); |
69 |
| - |
70 |
| -}tu_edpt_stream_t; |
71 |
| - |
72 |
| -// Init an stream, should only be called once |
73 |
| -bool tu_edpt_stream_init(tu_edpt_stream_t* s, bool is_host, bool is_tx, bool overwritable, |
74 |
| - void* ff_buf, uint16_t ff_bufsize, uint8_t* ep_buf, uint16_t ep_bufsize); |
75 |
| - |
76 |
| -// Open an stream for an endpoint |
77 |
| -// hwid is either device address (host mode) or rhport (device mode) |
78 |
| -TU_ATTR_ALWAYS_INLINE static inline |
79 |
| -void tu_edpt_stream_open(tu_edpt_stream_t* s, uint8_t hwid, tusb_desc_endpoint_t const *desc_ep) { |
80 |
| - tu_fifo_clear(&s->ff); |
81 |
| - s->hwid = hwid; |
82 |
| - s->ep_addr = desc_ep->bEndpointAddress; |
83 |
| - s->ep_packetsize = tu_edpt_packet_size(desc_ep); |
84 |
| -} |
85 |
| - |
86 |
| -TU_ATTR_ALWAYS_INLINE static inline |
87 |
| -void tu_edpt_stream_close(tu_edpt_stream_t* s) { |
88 |
| - s->hwid = 0; |
89 |
| - s->ep_addr = 0; |
90 |
| -} |
91 |
| - |
92 |
| -// Clear fifo |
93 |
| -TU_ATTR_ALWAYS_INLINE static inline |
94 |
| -bool tu_edpt_stream_clear(tu_edpt_stream_t* s) { |
95 |
| - return tu_fifo_clear(&s->ff); |
96 |
| -} |
97 |
| - |
98 |
| -//--------------------------------------------------------------------+ |
99 |
| -// Stream Write |
100 |
| -//--------------------------------------------------------------------+ |
101 |
| - |
102 |
| -// Write to stream |
103 |
| -uint32_t tu_edpt_stream_write(tu_edpt_stream_t* s, void const *buffer, uint32_t bufsize); |
104 |
| - |
105 |
| -// Start an usb transfer if endpoint is not busy |
106 |
| -uint32_t tu_edpt_stream_write_xfer(tu_edpt_stream_t* s); |
107 |
| - |
108 |
| -// Start an zero-length packet if needed |
109 |
| -bool tu_edpt_stream_write_zlp_if_needed(tu_edpt_stream_t* s, uint32_t last_xferred_bytes); |
110 |
| - |
111 |
| -// Get the number of bytes available for writing |
112 |
| -TU_ATTR_ALWAYS_INLINE static inline |
113 |
| -uint32_t tu_edpt_stream_write_available(tu_edpt_stream_t* s) |
114 |
| -{ |
115 |
| - return (uint32_t) tu_fifo_remaining(&s->ff); |
116 |
| -} |
117 |
| - |
118 |
| -//--------------------------------------------------------------------+ |
119 |
| -// Stream Read |
120 |
| -//--------------------------------------------------------------------+ |
121 |
| - |
122 |
| -// Read from stream |
123 |
| -uint32_t tu_edpt_stream_read(tu_edpt_stream_t* s, void* buffer, uint32_t bufsize); |
124 |
| - |
125 |
| -// Start an usb transfer if endpoint is not busy |
126 |
| -uint32_t tu_edpt_stream_read_xfer(tu_edpt_stream_t* s); |
127 |
| - |
128 |
| -// Must be called in the transfer complete callback |
129 |
| -TU_ATTR_ALWAYS_INLINE static inline |
130 |
| -void tu_edpt_stream_read_xfer_complete(tu_edpt_stream_t* s, uint32_t xferred_bytes) { |
131 |
| - tu_fifo_write_n(&s->ff, s->ep_buf, (uint16_t) xferred_bytes); |
132 |
| -} |
133 |
| - |
134 |
| -// Same as tu_edpt_stream_read_xfer_complete but skip the first n bytes |
135 |
| -TU_ATTR_ALWAYS_INLINE static inline |
136 |
| -void tu_edpt_stream_read_xfer_complete_offset(tu_edpt_stream_t* s, uint32_t xferred_bytes, uint32_t skip_offset) { |
137 |
| - if (skip_offset < xferred_bytes) { |
138 |
| - tu_fifo_write_n(&s->ff, s->ep_buf + skip_offset, (uint16_t) (xferred_bytes - skip_offset)); |
139 |
| - } |
140 |
| -} |
141 |
| - |
142 |
| -// Get the number of bytes available for reading |
143 |
| -TU_ATTR_ALWAYS_INLINE static inline |
144 |
| -uint32_t tu_edpt_stream_read_available(tu_edpt_stream_t* s) { |
145 |
| - return (uint32_t) tu_fifo_count(&s->ff); |
146 |
| -} |
147 |
| - |
148 |
| -TU_ATTR_ALWAYS_INLINE static inline |
149 |
| -bool tu_edpt_stream_peek(tu_edpt_stream_t* s, uint8_t* ch) { |
150 |
| - return tu_fifo_peek(&s->ff, ch); |
151 |
| -} |
152 |
| -#endif |
153 |
| -#endif |
154 |
| - |
155 | 39 | #include "cdc_host.h"
|
156 | 40 |
|
157 |
| - |
158 | 41 | // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
|
159 | 42 | #ifndef CFG_TUH_CDC_LOG_LEVEL
|
160 | 43 | #define CFG_TUH_CDC_LOG_LEVEL CFG_TUH_LOG_LEVEL
|
|
0 commit comments