Open FFBoard
Open source force feedback firmware
dcd_stm32_fsdev.c
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Nathan Conrad
5 *
6 * Portions:
7 * Copyright (c) 2019 Ha Thach (tinyusb.org)
8 * Copyright (c) 2022 Simon Küppers (skuep)
9 * Copyright (c) 2022 HiFiPhile
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * This file is part of the TinyUSB stack.
30 */
31
32/**********************************************
33 * This driver has been tested with the following MCUs:
34 * - F070, F072, L053, F042F6
35 *
36 * It also should work with minimal changes for any ST MCU with an "USB A"/"PCD"/"HCD" peripheral. This
37 * covers:
38 *
39 * F04x, F072, F078, F070x6/B 1024 byte buffer
40 * F102, F103 512 byte buffer; no internal D+ pull-up (maybe many more changes?)
41 * F302xB/C, F303xB/C, F373 512 byte buffer; no internal D+ pull-up
42 * F302x6/8, F302xD/E2, F303xD/E 1024 byte buffer; no internal D+ pull-up
43 * G0 2048 byte buffer; 32-bit bus; host mode
44 * G4 1024 byte buffer
45 * H5 2048 byte buffer; 32-bit bus; host mode
46 * L0x2, L0x3 1024 byte buffer
47 * L1 512 byte buffer
48 * L4x2, L4x3 1024 byte buffer
49 * L5 1024 byte buffer
50 * U0 1024 byte buffer; 32-bit bus
51 * U535, U545 2048 byte buffer; 32-bit bus; host mode
52 * WB35, WB55 1024 byte buffer
53 *
54 * To use this driver, you must:
55 * - If you are using a device with crystal-less USB, set up the clock recovery system (CRS)
56 * - Remap pins to be D+/D- on devices that they are shared (for example: F042Fx)
57 * - This is different to the normal "alternate function" GPIO interface, needs to go through SYSCFG->CFGRx register
58 * - Enable USB clock; Perhaps use __HAL_RCC_USB_CLK_ENABLE();
59 * - (Optionally configure GPIO HAL to tell it the USB driver is using the USB pins)
60 * - call tusb_init();
61 * - periodically call tusb_task();
62 *
63 * Assumptions of the driver:
64 * - You are not using CAN (it must share the packet buffer)
65 * - APB clock is >= 10 MHz
66 * - On some boards, series resistors are required, but not on others.
67 * - On some boards, D+ pull up resistor (1.5kohm) is required, but not on others.
68 * - You don't have long-running interrupts; some USB packets must be quickly responded to.
69 * - You have the ST CMSIS library linked into the project. HAL is not used.
70 *
71 * Current driver limitations (i.e., a list of features for you to add):
72 * - STALL handled, but not tested.
73 * - Does it work? No clue.
74 * - All EP BTABLE buffers are created based on max packet size of first EP opened with that address.
75 * - Packet buffer memory is copied in the interrupt.
76 * - This is better for performance, but means interrupts are disabled for longer
77 * - DMA may be the best choice, but it could also be pushed to the USBD task.
78 * - No double-buffering
79 * - No DMA
80 * - Minimal error handling
81 * - Perhaps error interrupts should be reported to the stack, or cause a device reset?
82 * - Assumes a single USB peripheral; I think that no hardware has multiple so this is fine.
83 * - Add a callback for enabling/disabling the D+ PU on devices without an internal PU.
84 * - F3 models use three separate interrupts. I think we could only use the LP interrupt for
85 * everything? However, the interrupts are configurable so the DisableInt and EnableInt
86 * below functions could be adjusting the wrong interrupts (if they had been reconfigured)
87 * - LPM is not used correctly, or at all?
88 *
89 * USB documentation and Reference implementations
90 * - STM32 Reference manuals
91 * - STM32 USB Hardware Guidelines AN4879
92 *
93 * - STM32 HAL (much of this driver is based on this)
94 * - libopencm3/lib/stm32/common/st_usbfs_core.c
95 * - Keil USB Device http://www.keil.com/pack/doc/mw/USB/html/group__usbd.html
96 *
97 * - YouTube OpenTechLab 011; https://www.youtube.com/watch?v=4FOkJLp_PUw
98 *
99 * Advantages over HAL driver:
100 * - Tiny (saves RAM, assumes a single USB peripheral)
101 *
102 * Notes:
103 * - The buffer table is allocated as endpoints are opened. The allocation is only
104 * cleared when the device is reset. This may be bad if the USB device needs
105 * to be reconfigured.
106 */
107
108#include "tusb_option.h"
109
110#if CFG_TUD_ENABLED && defined(TUP_USBIP_FSDEV) && \
111 !(defined(TUP_USBIP_FSDEV_CH32) && CFG_TUD_WCH_USBIP_FSDEV == 0)
112
113#include "device/dcd.h"
114
115#if defined(TUP_USBIP_FSDEV_STM32)
116 #include "fsdev_stm32.h"
117#elif defined(TUP_USBIP_FSDEV_CH32)
118 #include "fsdev_ch32.h"
119#else
120 #error "Unknown USB IP"
121#endif
122
123#include "fsdev_type.h"
124
125//--------------------------------------------------------------------+
126// MACRO CONSTANT TYPEDEF
127//--------------------------------------------------------------------+
128
129// One of these for every EP IN & OUT, uses a bit of RAM....
130typedef struct {
131 uint8_t *buffer;
133 uint16_t total_len;
134 uint16_t queued_len;
135 uint16_t max_packet_size;
136 uint8_t ep_idx; // index for USB_EPnR register
137 bool iso_in_sending; // Workaround for ISO IN EP doesn't have interrupt mask
138} xfer_ctl_t;
139
140// EP allocator
141typedef struct {
142 uint8_t ep_num;
143 uint8_t ep_type;
144 bool allocated[2];
145} ep_alloc_t;
146
147static xfer_ctl_t xfer_status[CFG_TUD_ENDPPOINT_MAX][2];
148static ep_alloc_t ep_alloc_status[FSDEV_EP_COUNT];
149static uint8_t remoteWakeCountdown; // When wake is requested
150
151//--------------------------------------------------------------------+
152// Prototypes
153//--------------------------------------------------------------------+
154
155// into the stack.
156static void handle_bus_reset(uint8_t rhport);
157static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix);
158static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, tusb_dir_t dir);
159
160// PMA allocation/access
161static uint16_t ep_buf_ptr;
162static uint32_t dcd_pma_alloc(uint16_t len, bool dbuf);
163static uint8_t dcd_ep_alloc(uint8_t ep_addr, uint8_t ep_type);
164static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, uint16_t nbytes);
165static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t nbytes);
166
167static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNBytes);
168static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBytes);
169
170static void edpt0_open(uint8_t rhport);
171
172TU_ATTR_ALWAYS_INLINE static inline void edpt0_prepare_setup(void) {
174}
175
176//--------------------------------------------------------------------+
177// Inline helper
178//--------------------------------------------------------------------+
179
180TU_ATTR_ALWAYS_INLINE static inline xfer_ctl_t *xfer_ctl_ptr(uint8_t epnum, uint8_t dir) {
181 return &xfer_status[epnum][dir];
182}
183
184//--------------------------------------------------------------------+
185// Controller API
186//--------------------------------------------------------------------+
187bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
188 (void) rh_init;
189 // Follow the RM mentions to use a special ordering of PDWN and FRES
190 for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
191 asm("NOP");
192 }
193
194 // Perform USB peripheral reset
195 FSDEV_REG->CNTR = USB_CNTR_FRES | USB_CNTR_PDWN;
196 for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
197 asm("NOP");
198 }
199
200 FSDEV_REG->CNTR &= ~USB_CNTR_PDWN;
201
202 // Wait startup time, for F042 and F070, this is <= 1 us.
203 for (volatile uint32_t i = 0; i < 200; i++) { // should be a few us
204 asm("NOP");
205 }
206 FSDEV_REG->CNTR = 0; // Enable USB
207
208#if !defined(FSDEV_BUS_32BIT)
209 // BTABLE register does not exist any more on 32-bit bus devices
210 FSDEV_REG->BTABLE = FSDEV_BTABLE_BASE;
211#endif
212
213 FSDEV_REG->ISTR = 0; // Clear pending interrupts
214
215 // Reset endpoints to disabled
216 for (uint32_t i = 0; i < FSDEV_EP_COUNT; i++) {
217 // This doesn't clear all bits since some bits are "toggle", but does set the type to DISABLED.
218 ep_write(i, 0u, false);
219 }
220
221 FSDEV_REG->CNTR |= USB_CNTR_RESETM | USB_CNTR_ESOFM | USB_CNTR_CTRM |
222 USB_CNTR_SUSPM | USB_CNTR_WKUPM | USB_CNTR_PMAOVRM;
223 handle_bus_reset(rhport);
224
225 // Enable pull-up if supported
226 dcd_connect(rhport);
227
228 return true;
229}
230
231void dcd_sof_enable(uint8_t rhport, bool en) {
232 (void)rhport;
233
234 if (en) {
235 FSDEV_REG->CNTR |= USB_CNTR_SOFM;
236 } else {
237 FSDEV_REG->CNTR &= ~USB_CNTR_SOFM;
238 }
239}
240
241// Receive Set Address request, mcu port must also include status IN response
242void dcd_set_address(uint8_t rhport, uint8_t dev_addr) {
243 (void)dev_addr;
244
245 // Respond with status
246 dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK | 0x00, NULL, 0);
247
248 // DCD can only set address after status for this request is complete.
249 // do it at dcd_edpt0_status_complete()
250}
251
252void dcd_remote_wakeup(uint8_t rhport) {
253 (void)rhport;
254
255 FSDEV_REG->CNTR |= USB_CNTR_RESUME;
256 remoteWakeCountdown = 4u; // required to be 1 to 15 ms, ESOF should trigger every 1ms.
257}
258
259static void handle_bus_reset(uint8_t rhport) {
260 FSDEV_REG->DADDR = 0u; // disable USB Function
261
262 for (uint32_t i = 0; i < FSDEV_EP_COUNT; i++) {
263 // Clear EP allocation status
264 ep_alloc_status[i].ep_num = 0xFF;
265 ep_alloc_status[i].ep_type = 0xFF;
266 ep_alloc_status[i].allocated[0] = false;
267 ep_alloc_status[i].allocated[1] = false;
268 }
269
270 // Reset PMA allocation
271 ep_buf_ptr = FSDEV_BTABLE_BASE + 8 * FSDEV_EP_COUNT;
272
273 edpt0_open(rhport); // open control endpoint (both IN & OUT)
274
275 FSDEV_REG->DADDR = USB_DADDR_EF; // Enable USB Function
276}
277
278// Handle CTR interrupt for the TX/IN direction
279static void handle_ctr_tx(uint32_t ep_id) {
280 uint32_t ep_reg = ep_read(ep_id) | USB_EP_CTR_TX | USB_EP_CTR_RX;
281
282 uint8_t const ep_num = ep_reg & USB_EPADDR_FIELD;
284
285 if (ep_is_iso(ep_reg)) {
286 // Ignore spurious interrupts that we don't schedule
287 // host can send IN token while there is no data to send, since ISO does not have NAK
288 // this will result to zero length packet --> trigger interrupt (which cannot be masked)
289 if (!xfer->iso_in_sending) {
290 return;
291 }
292 xfer->iso_in_sending = false;
293 uint8_t buf_id = (ep_reg & USB_EP_DTOG_TX) ? 0 : 1;
294 btable_set_count(ep_id, buf_id, 0);
295 }
296
297 if (xfer->total_len != xfer->queued_len) {
299 } else {
300 dcd_event_xfer_complete(0, ep_num | TUSB_DIR_IN_MASK, xfer->queued_len, XFER_RESULT_SUCCESS, true);
301 }
302}
303
304static void handle_ctr_setup(uint32_t ep_id) {
305 uint16_t rx_count = btable_get_count(ep_id, BTABLE_BUF_RX);
306 uint16_t rx_addr = btable_get_addr(ep_id, BTABLE_BUF_RX);
307 uint8_t setup_packet[8] TU_ATTR_ALIGNED(4);
308
309 dcd_read_packet_memory(setup_packet, rx_addr, rx_count);
310
311 // Clear CTR RX if another setup packet arrived before this, it will be discarded
313
314 // Setup packet should always be 8 bytes. If not, we probably missed the packet
315 if (rx_count == 8) {
316 dcd_event_setup_received(0, (uint8_t*) setup_packet, true);
317 // Hardware should reset EP0 RX/TX to NAK and both toggle to 1
318 } else {
319 // Missed setup packet !!!
320 TU_BREAKPOINT();
322 }
323}
324
325// Handle CTR interrupt for the RX/OUT direction
326static void handle_ctr_rx(uint32_t ep_id) {
327 uint32_t ep_reg = ep_read(ep_id) | USB_EP_CTR_TX | USB_EP_CTR_RX;
328 uint8_t const ep_num = ep_reg & USB_EPADDR_FIELD;
329 bool const is_iso = ep_is_iso(ep_reg);
331
332 uint8_t buf_id;
333 if (is_iso) {
334 buf_id = (ep_reg & USB_EP_DTOG_RX) ? 0 : 1; // ISO are double buffered
335 } else {
336 buf_id = BTABLE_BUF_RX;
337 }
338 uint16_t const rx_count = btable_get_count(ep_id, buf_id);
339 uint16_t pma_addr = (uint16_t) btable_get_addr(ep_id, buf_id);
340
341 if (xfer->ff) {
342 dcd_read_packet_memory_ff(xfer->ff, pma_addr, rx_count);
343 } else {
344 dcd_read_packet_memory(xfer->buffer + xfer->queued_len, pma_addr, rx_count);
345 }
346 xfer->queued_len += rx_count;
347
348 if ((rx_count < xfer->max_packet_size) || (xfer->queued_len >= xfer->total_len)) {
349 // all bytes received or short packet
350
351 // For ch32v203: reset rx bufsize to mps to prevent race condition to cause PMAOVR (occurs with msc write10)
352 btable_set_rx_bufsize(ep_id, BTABLE_BUF_RX, xfer->max_packet_size);
353
354 dcd_event_xfer_complete(0, ep_num, xfer->queued_len, XFER_RESULT_SUCCESS, true);
355
356 // ch32 seems to unconditionally accept ZLP on EP0 OUT, which can incorrectly use queued_len of previous
357 // transfer. So reset total_len and queued_len to 0.
358 xfer->total_len = xfer->queued_len = 0;
359 } else {
360 // Set endpoint active again for receiving more data. Note that isochronous endpoints stay active always
361 if (!is_iso) {
362 uint16_t const cnt = tu_min16(xfer->total_len - xfer->queued_len, xfer->max_packet_size);
364 }
365 ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(TUSB_DIR_OUT); // will change RX Status, reserved other toggle bits
367 ep_write(ep_id, ep_reg, false);
368 }
369}
370
371void dcd_int_handler(uint8_t rhport) {
372 uint32_t int_status = FSDEV_REG->ISTR;
373
374 /* Put SOF flag at the beginning of ISR in case to get least amount of jitter if it is used for timing purposes */
375 if (int_status & USB_ISTR_SOF) {
376 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_SOF;
377 dcd_event_sof(0, FSDEV_REG->FNR & USB_FNR_FN, true);
378 }
379
380 if (int_status & USB_ISTR_RESET) {
381 // USBRST is start of reset.
382 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_RESET;
383 handle_bus_reset(rhport);
385 return; // Don't do the rest of the things here; perhaps they've been cleared?
386 }
387
388 if (int_status & USB_ISTR_WKUP) {
389 FSDEV_REG->CNTR &= ~USB_CNTR_LPMODE;
390 FSDEV_REG->CNTR &= ~USB_CNTR_FSUSP;
391
392 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_WKUP;
393 dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
394 }
395
396 if (int_status & USB_ISTR_SUSP) {
397 /* Suspend is asserted for both suspend and unplug events. without Vbus monitoring,
398 * these events cannot be differentiated, so we only trigger suspend. */
399
400 /* Force low-power mode in the macrocell */
401 FSDEV_REG->CNTR |= USB_CNTR_FSUSP;
402 FSDEV_REG->CNTR |= USB_CNTR_LPMODE;
403
404 /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
405 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_SUSP;
406 dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
407 }
408
409 if (int_status & USB_ISTR_ESOF) {
410 if (remoteWakeCountdown == 1u) {
411 FSDEV_REG->CNTR &= ~USB_CNTR_RESUME;
412 }
413 if (remoteWakeCountdown > 0u) {
415 }
416 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_ESOF;
417 }
418
419 // loop to handle all pending CTR interrupts
420 while (FSDEV_REG->ISTR & USB_ISTR_CTR) {
421 // skip DIR bit, and use CTR TX/RX instead, since there is chance we have both TX/RX completed in one interrupt
422 uint32_t const ep_id = FSDEV_REG->ISTR & USB_ISTR_EP_ID;
423 uint32_t const ep_reg = ep_read(ep_id);
424
425 if (ep_reg & USB_EP_CTR_RX) {
426 #ifdef FSDEV_BUS_32BIT
427 /* https://www.st.com/resource/en/errata_sheet/es0561-stm32h503cbebkbrb-device-errata-stmicroelectronics.pdf
428 * https://www.st.com/resource/en/errata_sheet/es0587-stm32u535xx-and-stm32u545xx-device-errata-stmicroelectronics.pdf
429 * From H503/U535 errata: Buffer description table update completes after CTR interrupt triggers
430 * Description:
431 * - During OUT transfers, the correct transfer interrupt (CTR) is triggered a little before the last USB SRAM accesses
432 * have completed. If the software responds quickly to the interrupt, the full buffer contents may not be correct.
433 * Workaround:
434 * - Software should ensure that a small delay is included before accessing the SRAM contents. This delay
435 * should be 800 ns in Full Speed mode and 6.4 μs in Low Speed mode
436 * - Since H5 can run up to 250Mhz -> 1 cycle = 4ns. Per errata, we need to wait 200 cycles. Though executing code
437 * also takes time, so we'll wait 60 cycles (count = 20).
438 * - Since Low Speed mode is not supported/popular, we will ignore it for now.
439 *
440 * Note: this errata may also apply to G0, U5, H5 etc.
441 */
442 volatile uint32_t cycle_count = 20; // defined as PCD_RX_PMA_CNT in stm32 hal_driver
443 while (cycle_count > 0U) {
444 cycle_count--; // each count take 3 cycles (1 for sub, jump, and compare)
445 }
446 #endif
447
448 if (ep_reg & USB_EP_SETUP) {
449 handle_ctr_setup(ep_id); // CTR will be clear after copied setup packet
450 } else {
452 handle_ctr_rx(ep_id);
453 }
454 }
455
456 if (ep_reg & USB_EP_CTR_TX) {
458 handle_ctr_tx(ep_id);
459 }
460 }
461
462 if (int_status & USB_ISTR_PMAOVR) {
463 TU_BREAKPOINT();
464 FSDEV_REG->ISTR = (fsdev_bus_t)~USB_ISTR_PMAOVR;
465 }
466}
467
468//--------------------------------------------------------------------+
469// Endpoint API
470//--------------------------------------------------------------------+
471
472// Invoked when a control transfer's status stage is complete.
473// May help DCD to prepare for next control transfer, this API is optional.
475 (void)rhport;
476
480 uint8_t const dev_addr = (uint8_t)request->wValue;
481 FSDEV_REG->DADDR = (USB_DADDR_EF | dev_addr);
482 }
483
485}
486
487/***
488 * Allocate a section of PMA
489 * In case of double buffering, high 16bit is the address of 2nd buffer
490 * During failure, TU_ASSERT is used. If this happens, rework/reallocate memory manually.
491 */
492static uint32_t dcd_pma_alloc(uint16_t len, bool dbuf)
493{
494 uint8_t blsize, num_block;
495 uint16_t aligned_len = pma_align_buffer_size(len, &blsize, &num_block);
496 (void) blsize;
497 (void) num_block;
498
499 uint32_t addr = ep_buf_ptr;
500 ep_buf_ptr = (uint16_t)(ep_buf_ptr + aligned_len); // increment buffer pointer
501
502 if (dbuf) {
503 addr |= ((uint32_t)ep_buf_ptr) << 16;
504 ep_buf_ptr = (uint16_t)(ep_buf_ptr + aligned_len); // increment buffer pointer
505 }
506
507 // Verify packet buffer is not overflowed
508 TU_ASSERT(ep_buf_ptr <= FSDEV_PMA_SIZE, 0xFFFF);
509
510 return addr;
511}
512
513/***
514 * Allocate hardware endpoint
515 */
516static uint8_t dcd_ep_alloc(uint8_t ep_addr, uint8_t ep_type)
517{
518 uint8_t const epnum = tu_edpt_number(ep_addr);
519 uint8_t const dir = tu_edpt_dir(ep_addr);
520
521 for (uint8_t i = 0; i < FSDEV_EP_COUNT; i++) {
522 // Check if already allocated
523 if (ep_alloc_status[i].allocated[dir] &&
524 ep_alloc_status[i].ep_type == ep_type &&
525 ep_alloc_status[i].ep_num == epnum) {
526 return i;
527 }
528
529 // If EP of current direction is not allocated
530 // Except for ISO endpoint, both direction should be free
531 if (!ep_alloc_status[i].allocated[dir] &&
532 (ep_type != TUSB_XFER_ISOCHRONOUS || !ep_alloc_status[i].allocated[dir ^ 1])) {
533 // Check if EP number is the same
534 if (ep_alloc_status[i].ep_num == 0xFF || ep_alloc_status[i].ep_num == epnum) {
535 // One EP pair has to be the same type
536 if (ep_alloc_status[i].ep_type == 0xFF || ep_alloc_status[i].ep_type == ep_type) {
537 ep_alloc_status[i].ep_num = epnum;
538 ep_alloc_status[i].ep_type = ep_type;
539 ep_alloc_status[i].allocated[dir] = true;
540
541 return i;
542 }
543 }
544 }
545 }
546
547 // Allocation failed
548 TU_ASSERT(0);
549}
550
551void edpt0_open(uint8_t rhport) {
552 (void) rhport;
553
556
557 xfer_status[0][0].max_packet_size = CFG_TUD_ENDPOINT0_SIZE;
558 xfer_status[0][0].ep_idx = 0;
559
560 xfer_status[0][1].max_packet_size = CFG_TUD_ENDPOINT0_SIZE;
561 xfer_status[0][1].ep_idx = 0;
562
563 uint16_t pma_addr0 = dcd_pma_alloc(CFG_TUD_ENDPOINT0_SIZE, false);
564 uint16_t pma_addr1 = dcd_pma_alloc(CFG_TUD_ENDPOINT0_SIZE, false);
565
566 btable_set_addr(0, BTABLE_BUF_RX, pma_addr0);
567 btable_set_addr(0, BTABLE_BUF_TX, pma_addr1);
568
569 uint32_t ep_reg = ep_read(0) & ~USB_EPREG_MASK; // only get toggle bits
570 ep_reg |= USB_EP_CONTROL;
573 // no need to explicitly set DTOG bits since we aren't masked DTOG bit
574
575 edpt0_prepare_setup(); // prepare for setup packet
576 ep_write(0, ep_reg, false);
577}
578
579bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep) {
580 (void)rhport;
581 uint8_t const ep_addr = desc_ep->bEndpointAddress;
582 uint8_t const ep_num = tu_edpt_number(ep_addr);
583 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
584 const uint16_t packet_size = tu_edpt_packet_size(desc_ep);
585 uint8_t const ep_idx = dcd_ep_alloc(ep_addr, desc_ep->bmAttributes.xfer);
586 TU_ASSERT(ep_idx < FSDEV_EP_COUNT);
587
588 uint32_t ep_reg = ep_read(ep_idx) & ~USB_EPREG_MASK;
589 ep_reg |= tu_edpt_number(ep_addr) | USB_EP_CTR_TX | USB_EP_CTR_RX;
590
591 // Set type
592 switch (desc_ep->bmAttributes.xfer) {
593 case TUSB_XFER_BULK:
594 ep_reg |= USB_EP_BULK;
595 break;
597 ep_reg |= USB_EP_INTERRUPT;
598 break;
599
600 default:
601 // Note: ISO endpoint should use alloc / active functions
602 TU_ASSERT(false);
603 }
604
605 /* Create a packet memory buffer area. */
606 uint16_t pma_addr = dcd_pma_alloc(packet_size, false);
607 btable_set_addr(ep_idx, dir == TUSB_DIR_IN ? BTABLE_BUF_TX : BTABLE_BUF_RX, pma_addr);
608
609 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
610 xfer->max_packet_size = packet_size;
611 xfer->ep_idx = ep_idx;
612
613 ep_change_status(&ep_reg, dir, EP_STAT_NAK);
614 ep_change_dtog(&ep_reg, dir, 0);
615
616 // reserve other direction toggle bits
617 if (dir == TUSB_DIR_IN) {
618 ep_reg &= ~(USB_EPRX_STAT | USB_EP_DTOG_RX);
619 } else {
620 ep_reg &= ~(USB_EPTX_STAT | USB_EP_DTOG_TX);
621 }
622
623 ep_write(ep_idx, ep_reg, true);
624
625 return true;
626}
627
628void dcd_edpt_close_all(uint8_t rhport) {
629 dcd_int_disable(rhport);
630
631 for (uint32_t i = 1; i < FSDEV_EP_COUNT; i++) {
632 // Reset endpoint
633 ep_write(i, 0, false);
634 // Clear EP allocation status
635 ep_alloc_status[i].ep_num = 0xFF;
636 ep_alloc_status[i].ep_type = 0xFF;
637 ep_alloc_status[i].allocated[0] = false;
638 ep_alloc_status[i].allocated[1] = false;
639 }
640
641 dcd_int_enable(rhport);
642
643 // Reset PMA allocation
644 ep_buf_ptr = FSDEV_BTABLE_BASE + 8 * CFG_TUD_ENDPPOINT_MAX + 2 * CFG_TUD_ENDPOINT0_SIZE;
645}
646
647bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
648 (void)rhport;
649
650 uint8_t const ep_num = tu_edpt_number(ep_addr);
651 uint8_t const dir = tu_edpt_dir(ep_addr);
652 uint8_t const ep_idx = dcd_ep_alloc(ep_addr, TUSB_XFER_ISOCHRONOUS);
653
654 /* Create a packet memory buffer area. Enable double buffering for devices with 2048 bytes PMA,
655 for smaller devices double buffering occupy too much space. */
656#if FSDEV_PMA_SIZE > 1024u
657 uint32_t pma_addr = dcd_pma_alloc(largest_packet_size, true);
658 uint16_t pma_addr2 = pma_addr >> 16;
659#else
660 uint32_t pma_addr = dcd_pma_alloc(largest_packet_size, false);
661 uint16_t pma_addr2 = pma_addr;
662#endif
663
664 btable_set_addr(ep_idx, 0, pma_addr);
665 btable_set_addr(ep_idx, 1, pma_addr2);
666
667 xfer_ctl_t* xfer = xfer_ctl_ptr(ep_num, dir);
668 xfer->ep_idx = ep_idx;
669
670 return true;
671}
672
673bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep) {
674 (void)rhport;
675 uint8_t const ep_addr = desc_ep->bEndpointAddress;
676 uint8_t const ep_num = tu_edpt_number(ep_addr);
677 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
678 xfer_ctl_t* xfer = xfer_ctl_ptr(ep_num, dir);
679
680 uint8_t const ep_idx = xfer->ep_idx;
681
682 xfer->max_packet_size = tu_edpt_packet_size(desc_ep);
683
684 uint32_t ep_reg = ep_read(ep_idx) & ~USB_EPREG_MASK;
685 ep_reg |= tu_edpt_number(ep_addr) | USB_EP_ISOCHRONOUS | USB_EP_CTR_TX | USB_EP_CTR_RX;
688 ep_change_dtog(&ep_reg, dir, 0);
689 ep_change_dtog(&ep_reg, (tusb_dir_t)(1 - dir), 1);
690
691 ep_write(ep_idx, ep_reg, true);
692
693 return true;
694}
695
696// Currently, single-buffered, and only 64 bytes at a time (max)
697static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix) {
698 uint16_t len = tu_min16(xfer->total_len - xfer->queued_len, xfer->max_packet_size);
699 uint32_t ep_reg = ep_read(ep_ix) | USB_EP_CTR_TX | USB_EP_CTR_RX; // reserve CTR
700
701 bool const is_iso = ep_is_iso(ep_reg);
702
703 uint8_t buf_id;
704 if (is_iso) {
705 buf_id = (ep_reg & USB_EP_DTOG_TX) ? 1 : 0;
706 } else {
707 buf_id = BTABLE_BUF_TX;
708 }
709 uint16_t addr_ptr = (uint16_t) btable_get_addr(ep_ix, buf_id);
710
711 if (xfer->ff) {
712 dcd_write_packet_memory_ff(xfer->ff, addr_ptr, len);
713 } else {
714 dcd_write_packet_memory(addr_ptr, &(xfer->buffer[xfer->queued_len]), len);
715 }
716 xfer->queued_len += len;
717
718 btable_set_count(ep_ix, buf_id, len);
720
721 if (is_iso) {
722 xfer->iso_in_sending = true;
723 }
724 ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(TUSB_DIR_IN); // only change TX Status, reserve other toggle bits
725 ep_write(ep_ix, ep_reg, true);
726}
727
728static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, tusb_dir_t dir) {
729 (void) rhport;
730
731 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
732 uint8_t const ep_idx = xfer->ep_idx;
733
734 if (dir == TUSB_DIR_IN) {
735 dcd_transmit_packet(xfer, ep_idx);
736 } else {
737 uint32_t ep_reg = ep_read(ep_idx) | USB_EP_CTR_TX | USB_EP_CTR_RX; // reserve CTR
738 ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(dir);
739
740 uint16_t cnt = tu_min16(xfer->total_len, xfer->max_packet_size);
741
742 if (ep_is_iso(ep_reg)) {
743 btable_set_rx_bufsize(ep_idx, 0, cnt);
744 btable_set_rx_bufsize(ep_idx, 1, cnt);
745 } else {
747 }
748
749 ep_change_status(&ep_reg, dir, EP_STAT_VALID);
750 ep_write(ep_idx, ep_reg, true);
751 }
752
753 return true;
754}
755
756bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes) {
757 uint8_t const ep_num = tu_edpt_number(ep_addr);
758 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
759 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
760
761 xfer->buffer = buffer;
762 xfer->ff = NULL;
764 xfer->queued_len = 0;
765
766 return edpt_xfer(rhport, ep_num, dir);
767}
768
769bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t total_bytes) {
770 uint8_t const ep_num = tu_edpt_number(ep_addr);
771 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
772 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
773
774 xfer->buffer = NULL;
775 xfer->ff = ff;
777 xfer->queued_len = 0;
778
779 return edpt_xfer(rhport, ep_num, dir);
780}
781
782void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
783 (void)rhport;
784 uint8_t const ep_num = tu_edpt_number(ep_addr);
785 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
786 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
787 uint8_t const ep_idx = xfer->ep_idx;
788
789 uint32_t ep_reg = ep_read(ep_idx) | USB_EP_CTR_TX | USB_EP_CTR_RX; // reserve CTR bits
790 ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(dir);
791 ep_change_status(&ep_reg, dir, EP_STAT_STALL);
792
793 ep_write(ep_idx, ep_reg, true);
794}
795
796void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
797 (void)rhport;
798
799 uint8_t const ep_num = tu_edpt_number(ep_addr);
800 tusb_dir_t const dir = tu_edpt_dir(ep_addr);
801 xfer_ctl_t *xfer = xfer_ctl_ptr(ep_num, dir);
802 uint8_t const ep_idx = xfer->ep_idx;
803
804 uint32_t ep_reg = ep_read(ep_idx) | USB_EP_CTR_TX | USB_EP_CTR_RX; // reserve CTR bits
805 ep_reg &= USB_EPREG_MASK | EP_STAT_MASK(dir) | EP_DTOG_MASK(dir);
806
807 if (!ep_is_iso(ep_reg)) {
808 ep_change_status(&ep_reg, dir, EP_STAT_NAK);
809 }
810 ep_change_dtog(&ep_reg, dir, 0); // Reset to DATA0
811 ep_write(ep_idx, ep_reg, true);
812}
813
814//--------------------------------------------------------------------+
815// PMA read/write
816//--------------------------------------------------------------------+
817
818// Write to packet memory area (PMA) from user memory
819// - Packet memory must be either strictly 16-bit or 32-bit depending on FSDEV_BUS_32BIT
820// - Uses unaligned for RAM (since M0 cannot access unaligned address)
821static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, uint16_t nbytes) {
822 if (nbytes == 0) return true;
823 uint32_t n_write = nbytes / FSDEV_BUS_SIZE;
824
825 fsdev_pma_buf_t* pma_buf = PMA_BUF_AT(dst);
826 const uint8_t *src8 = src;
827
828 while (n_write--) {
829 pma_buf->value = fsdevbus_unaligned_read(src8);
830 src8 += FSDEV_BUS_SIZE;
831 pma_buf++;
832 }
833
834 // odd bytes e.g 1 for 16-bit or 1-3 for 32-bit
835 uint16_t odd = nbytes & (FSDEV_BUS_SIZE - 1);
836 if (odd) {
837 fsdev_bus_t temp = 0;
838 for(uint16_t i = 0; i < odd; i++) {
839 temp |= *src8++ << (i * 8);
840 }
841 pma_buf->value = temp;
842 }
843
844 return true;
845}
846
847// Read from packet memory area (PMA) to user memory.
848// - Packet memory must be either strictly 16-bit or 32-bit depending on FSDEV_BUS_32BIT
849// - Uses unaligned for RAM (since M0 cannot access unaligned address)
850static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t nbytes) {
851 if (nbytes == 0) return true;
852 uint32_t n_read = nbytes / FSDEV_BUS_SIZE;
853
854 fsdev_pma_buf_t* pma_buf = PMA_BUF_AT(src);
855 uint8_t *dst8 = (uint8_t *)dst;
856
857 while (n_read--) {
858 fsdevbus_unaligned_write(dst8, (fsdev_bus_t ) pma_buf->value);
859 dst8 += FSDEV_BUS_SIZE;
860 pma_buf++;
861 }
862
863 // odd bytes e.g 1 for 16-bit or 1-3 for 32-bit
864 uint16_t odd = nbytes & (FSDEV_BUS_SIZE - 1);
865 if (odd) {
866 fsdev_bus_t temp = pma_buf->value;
867 while (odd--) {
868 *dst8++ = (uint8_t) (temp & 0xfful);
869 temp >>= 8;
870 }
871 }
872
873 return true;
874}
875
876// Write to PMA from FIFO
877static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNBytes) {
878 if (wNBytes == 0) return true;
879
880 // Since we copy from a ring buffer FIFO, a wrap might occur making it necessary to conduct two copies
883
884 uint16_t cnt_lin = tu_min16(wNBytes, info.len_lin);
885 uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.len_wrap);
886 uint16_t const cnt_total = cnt_lin + cnt_wrap;
887
888 // We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
889 // last lin byte will be combined with wrapped part To ensure PMA is always access aligned
890 uint16_t lin_even = cnt_lin & ~(FSDEV_BUS_SIZE - 1);
891 uint16_t lin_odd = cnt_lin & (FSDEV_BUS_SIZE - 1);
892 uint8_t const *src8 = (uint8_t const*) info.ptr_lin;
893
894 // write even linear part
895 dcd_write_packet_memory(dst, src8, lin_even);
896 dst += lin_even;
897 src8 += lin_even;
898
899 if (lin_odd == 0) {
900 src8 = (uint8_t const*) info.ptr_wrap;
901 } else {
902 // Combine last linear bytes + first wrapped bytes to form fsdev bus width data
903 fsdev_bus_t temp = 0;
904 uint16_t i;
905 for(i = 0; i < lin_odd; i++) {
906 temp |= *src8++ << (i * 8);
907 }
908
909 src8 = (uint8_t const*) info.ptr_wrap;
910 for(; i < FSDEV_BUS_SIZE && cnt_wrap > 0; i++, cnt_wrap--) {
911 temp |= *src8++ << (i * 8);
912 }
913
915 dst += FSDEV_BUS_SIZE;
916 }
917
918 // write the rest of the wrapped part
919 dcd_write_packet_memory(dst, src8, cnt_wrap);
920
921 tu_fifo_advance_read_pointer(ff, cnt_total);
922 return true;
923}
924
925// Read from PMA to FIFO
926static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBytes) {
927 if (wNBytes == 0) return true;
928
929 // Since we copy into a ring buffer FIFO, a wrap might occur making it necessary to conduct two copies
930 // Check for first linear part
932 tu_fifo_get_write_info(ff, &info); // We want to read from the FIFO
933
934 uint16_t cnt_lin = tu_min16(wNBytes, info.len_lin);
935 uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.len_wrap);
936 uint16_t cnt_total = cnt_lin + cnt_wrap;
937
938 // We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
939 // last lin byte will be combined with wrapped part To ensure PMA is always access aligned
940
941 uint16_t lin_even = cnt_lin & ~(FSDEV_BUS_SIZE - 1);
942 uint16_t lin_odd = cnt_lin & (FSDEV_BUS_SIZE - 1);
943 uint8_t *dst8 = (uint8_t *) info.ptr_lin;
944
945 // read even linear part
946 dcd_read_packet_memory(dst8, src, lin_even);
947 dst8 += lin_even;
948 src += lin_even;
949
950 if (lin_odd == 0) {
951 dst8 = (uint8_t *) info.ptr_wrap;
952 } else {
953 // Combine last linear bytes + first wrapped bytes to form fsdev bus width data
956 src += FSDEV_BUS_SIZE;
957
958 uint16_t i;
959 for (i = 0; i < lin_odd; i++) {
960 *dst8++ = (uint8_t) (temp & 0xfful);
961 temp >>= 8;
962 }
963
964 dst8 = (uint8_t *) info.ptr_wrap;
965 for (; i < FSDEV_BUS_SIZE && cnt_wrap > 0; i++, cnt_wrap--) {
966 *dst8++ = (uint8_t) (temp & 0xfful);
967 temp >>= 8;
968 }
969 }
970
971 // read the rest of the wrapped part
972 dcd_read_packet_memory(dst8, src, cnt_wrap);
973
974 tu_fifo_advance_write_pointer(ff, cnt_total);
975 return true;
976}
977
978#endif
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_signal(uint8_t rhport, dcd_eventid_t eid, bool in_isr)
Definition: dcd.h:196
static TU_ATTR_ALWAYS_INLINE void dcd_event_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
Definition: dcd.h:222
static TU_ATTR_ALWAYS_INLINE void dcd_event_sof(uint8_t rhport, uint32_t frame_count, bool in_isr)
Definition: dcd.h:232
static TU_ATTR_ALWAYS_INLINE void dcd_event_setup_received(uint8_t rhport, uint8_t const *setup, bool in_isr)
Definition: dcd.h:213
void dcd_int_disable(uint8_t rhport)
Definition: dcd_samd.c:138
void dcd_connect(uint8_t rhport)
Definition: fsdev_stm32.h:349
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_reset(uint8_t rhport, tusb_speed_t speed, bool in_isr)
Definition: dcd.h:204
struct TU_ATTR_ALIGNED(4)
Definition: dcd.h:55
void dcd_int_enable(uint8_t rhport)
Definition: dcd_samd.c:132
xfer_ctl_t
Definition: dcd_dwc2.c:52
static TU_ATTR_ALWAYS_INLINE bool ep_is_iso(ep_cmd_sts_t *ep_cs, bool is_highspeed)
xfer_td_t xfer[EP_CBI_COUNT+1][2]
Definition: dcd_nrf5x.c:119
uint16_t total_bytes
Definition: dcd_nuc505.c:113
uint8_t dev_addr
Definition: dcd_pic32mz.c:81
static ep_reg_t ep_read(uint8_t rhport, uint8_t ep_num)
Definition: dcd_pic.c:220
static void ep_write(uint8_t rhport, uint8_t ep_num, ep_reg_t val)
Definition: dcd_pic.c:225
static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNBytes)
bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
static xfer_ctl_t xfer_status[CFG_TUD_ENDPPOINT_MAX][2]
bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t total_bytes)
static bool edpt_xfer(uint8_t rhport, uint8_t ep_num, tusb_dir_t dir)
static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, uint16_t nbytes)
static uint8_t remoteWakeCountdown
static TU_ATTR_ALWAYS_INLINE void edpt0_prepare_setup(void)
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBytes)
void dcd_int_handler(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE xfer_ctl_t * xfer_ctl_ptr(uint8_t epnum, uint8_t dir)
void dcd_edpt_close_all(uint8_t rhport)
static void handle_ctr_setup(uint32_t ep_id)
static void dcd_transmit_packet(xfer_ctl_t *xfer, uint16_t ep_ix)
static void edpt0_open(uint8_t rhport)
static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t nbytes)
static void handle_ctr_tx(uint32_t ep_id)
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
static uint8_t dcd_ep_alloc(uint8_t ep_addr, uint8_t ep_type)
static void handle_ctr_rx(uint32_t ep_id)
static void handle_bus_reset(uint8_t rhport)
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const *request)
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t *rh_init)
static ep_alloc_t ep_alloc_status[FSDEV_EP_COUNT]
static uint16_t ep_buf_ptr
Points to first free memory location.
bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size)
static uint32_t dcd_pma_alloc(uint16_t len, bool dbuf)
void dcd_remote_wakeup(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
static TU_ATTR_ALWAYS_INLINE uint16_t pma_align_buffer_size(uint16_t size, uint8_t *blsize, uint8_t *num_block)
Definition: fsdev_type.h:264
static TU_ATTR_ALWAYS_INLINE void btable_set_count(uint32_t ep_id, uint8_t buf_id, uint16_t byte_count)
Definition: fsdev_type.h:251
@ EP_STAT_STALL
Definition: fsdev_type.h:169
@ EP_STAT_VALID
Definition: fsdev_type.h:171
@ EP_STAT_DISABLED
Definition: fsdev_type.h:168
@ EP_STAT_NAK
Definition: fsdev_type.h:170
static TU_ATTR_ALWAYS_INLINE void ep_change_status(uint32_t *reg, tusb_dir_t dir, ep_stat_t state)
Definition: fsdev_type.h:207
uint32_t fsdev_bus_t
Definition: fsdev_type.h:68
static TU_ATTR_ALWAYS_INLINE void btable_set_addr(uint32_t ep_id, uint8_t buf_id, uint16_t addr)
Definition: fsdev_type.h:231
static TU_ATTR_ALWAYS_INLINE void btable_set_rx_bufsize(uint32_t ep_id, uint8_t buf_id, uint16_t wCount)
Definition: fsdev_type.h:281
static TU_ATTR_ALWAYS_INLINE uint32_t btable_get_addr(uint32_t ep_id, uint8_t buf_id)
Definition: fsdev_type.h:223
static TU_ATTR_ALWAYS_INLINE void ep_change_dtog(uint32_t *reg, tusb_dir_t dir, uint8_t state)
Definition: fsdev_type.h:211
static TU_ATTR_ALWAYS_INLINE void ep_write_clear_ctr(uint32_t ep_id, tusb_dir_t dir)
Definition: fsdev_type.h:199
static TU_ATTR_ALWAYS_INLINE uint16_t btable_get_count(uint32_t ep_id, uint8_t buf_id)
Definition: fsdev_type.h:241
@ BTABLE_BUF_RX
Definition: fsdev_type.h:86
@ BTABLE_BUF_TX
Definition: fsdev_type.h:85
@ FSDEV_BUS_SIZE
Definition: fsdev_type.h:78
uint8_t const * buffer
Definition: midi_device.h:100
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint16_t wValue
Definition: audio.h:934
struct TU_ATTR_PACKED::@16::TU_ATTR_PACKED bmRequestType_bit
uint8_t bmAttributes
See: audio_clock_source_attribute_t.
Definition: audio.h:672
uint8_t bEndpointAddress
Definition: video.h:306
uint8_t bRequest
Request type audio_cs_req_t.
Definition: audio.h:831
uint8_t ep_num
uint8_t ep_type
bool allocated[2]
volatile pma_access_scheme fsdev_bus_t value
Definition: fsdev_type.h:114
tu_fifo_t * ff
uint16_t max_packet_size
Definition: dcd_da146xx.c:216
uint8_t ep_idx
uint16_t total_len
Definition: dcd_nrf5x.c:100
uint8_t * buffer
Definition: dcd_nrf5x.c:99
static TU_ATTR_ALWAYS_INLINE uint16_t tu_min16(uint16_t x, uint16_t y)
Definition: tusb_common.h:155
void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Get linear write info.
Definition: tusb_fifo.c:1057
void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n)
Advance write pointer - intended to be used in combination with DMA. It is possible to fill the FIFO ...
Definition: tusb_fifo.c:948
void tu_fifo_advance_read_pointer(tu_fifo_t *f, uint16_t n)
Advance read pointer - intended to be used in combination with DMA. It is possible to read from the F...
Definition: tusb_fifo.c:969
void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Get read info.
Definition: tusb_fifo.c:989
tusb_dir_t
Definition: tusb_types.h:65
@ TUSB_DIR_IN
Definition: tusb_types.h:67
@ TUSB_DIR_OUT
Definition: tusb_types.h:66
@ TUSB_DIR_IN_MASK
Definition: tusb_types.h:69
@ TUSB_REQ_SET_ADDRESS
Definition: tusb_types.h:127
@ TUSB_SPEED_FULL
Definition: tusb_types.h:50
static TU_ATTR_ALWAYS_INLINE uint8_t tu_edpt_number(uint8_t addr)
Definition: tusb_types.h:507
@ XFER_RESULT_SUCCESS
Definition: tusb_types.h:237
@ TUSB_REQ_RCPT_DEVICE
Definition: tusb_types.h:151
static TU_ATTR_ALWAYS_INLINE uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const *desc_ep)
Definition: tusb_types.h:515
@ TUSB_XFER_CONTROL
Definition: tusb_types.h:59
@ TUSB_XFER_ISOCHRONOUS
Definition: tusb_types.h:60
@ TUSB_XFER_INTERRUPT
Definition: tusb_types.h:62
@ TUSB_XFER_BULK
Definition: tusb_types.h:61
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
Definition: tusb_types.h:502
@ TUSB_REQ_TYPE_STANDARD
Definition: tusb_types.h:144
CFG_TUH_MEM_ALIGN tusb_control_request_t request
Definition: usbh.c:259