Skip to content

Commit

Permalink
add >64 byte packet support for ep3
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonlock2 committed Dec 14, 2023
1 parent c25c755 commit 8f50811
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/portable/wch/dcd_ch32_usbfs.c
Expand Up @@ -28,6 +28,12 @@ static struct {
bool isochronous[EP_MAX];
struct usb_xfer xfer[EP_MAX][2];
TU_ATTR_ALIGNED(4) uint8_t buffer[EP_MAX][2][64];
TU_ATTR_ALIGNED(4) struct {
// OUT transfers >64 bytes will overwrite queued IN data!
uint8_t out[64];
uint8_t in[1023];
uint8_t pad;
} ep3_buffer;
} data;

/* private helpers */
Expand All @@ -38,6 +44,8 @@ static void update_in(uint8_t rhport, uint8_t ep, bool force) {
size_t len = TU_MIN(xfer->max_size, xfer->len);
if (ep == 0) {
memcpy(data.buffer[ep][TUSB_DIR_OUT], xfer->buffer, len); // ep0 uses same chunk
} else if (ep == 3) {
memcpy(data.ep3_buffer.in, xfer->buffer, len);
} else {
memcpy(data.buffer[ep][TUSB_DIR_IN], xfer->buffer, len);
}
Expand Down Expand Up @@ -67,7 +75,11 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) {
struct usb_xfer *xfer = &data.xfer[ep][TUSB_DIR_OUT];
if (xfer->valid) {
size_t len = TU_MIN(xfer->max_size, TU_MIN(xfer->len, rx_len));
memcpy(xfer->buffer, data.buffer[ep][TUSB_DIR_OUT], len);
if (ep == 3) {
memcpy(xfer->buffer, data.ep3_buffer.out, len);
} else {
memcpy(xfer->buffer, data.buffer[ep][TUSB_DIR_OUT], len);
}
xfer->buffer += len;
xfer->len -= len;
xfer->processed_len += len;
Expand Down Expand Up @@ -111,6 +123,7 @@ void dcd_init(uint8_t rhport) {
EP_TX_CTRL(ep) = USBFS_EP_T_AUTO_TOG | USBFS_EP_T_RES_NAK;
EP_RX_CTRL(ep) = USBFS_EP_R_AUTO_TOG | USBFS_EP_R_RES_NAK;
}
EP_DMA(3) = (uint32_t) &data.ep3_buffer.out[0];

dcd_connect(rhport);
}
Expand Down

0 comments on commit 8f50811

Please sign in to comment.