use CFG_TUD_ENDPOINT0_SIZE, rename ep0_data_in_out_buffer to simply ep0_buffer

reformat indent to 2 spaces
This commit is contained in:
hathach 2024-05-21 15:41:59 +07:00
parent 3e604d1d54
commit 4bd72da5cd
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52

View File

@ -35,7 +35,6 @@
// Max number of bi-directional endpoints including EP0
#define EP_MAX 16
#define CH32_USBHS_EP0_MAX_SIZE (64)
typedef struct {
uint8_t* buffer;
@ -63,7 +62,7 @@ static xfer_ctl_t xfer_status[EP_MAX][2];
#define EP_RX_DMA_ADDR(ep) *(volatile uint32_t *)((volatile uint32_t *)&(USBHSD->UEP1_RX_DMA) + (ep - 1))
/* Endpoint Buffer */
TU_ATTR_ALIGNED(4) static uint8_t ep0_data_in_out_buffer[CH32_USBHS_EP0_MAX_SIZE];
TU_ATTR_ALIGNED(4) static uint8_t ep0_buffer[CFG_TUD_ENDPOINT0_SIZE];
static void ep_set_response_and_toggle(uint8_t ep_addr, ep_response_list_t response_type) {
uint8_t const ep_num = tu_edpt_number(ep_addr);
@ -107,7 +106,7 @@ static void xfer_data_packet(uint8_t ep_addr, xfer_ctl_t *xfer) {
uint16_t next_tx_size = TU_MIN(remaining, xfer->max_size);
if (ep_num == 0) {
memcpy(ep0_data_in_out_buffer, &xfer->buffer[xfer->queued_len], next_tx_size);
memcpy(ep0_buffer, &xfer->buffer[xfer->queued_len], next_tx_size);
} else {
EP_TX_DMA_ADDR(ep_num) = (uint32_t) &xfer->buffer[xfer->queued_len];
}
@ -169,10 +168,10 @@ void dcd_init(uint8_t rhport) {
EP_RX_MAX_LEN(ep) = 0;
}
USBHSD->UEP0_DMA = (uint32_t)ep0_data_in_out_buffer;
USBHSD->UEP0_MAX_LEN = CH32_USBHS_EP0_MAX_SIZE;
xfer_status[0][TUSB_DIR_OUT].max_size = CH32_USBHS_EP0_MAX_SIZE;
xfer_status[0][TUSB_DIR_IN].max_size = CH32_USBHS_EP0_MAX_SIZE;
USBHSD->UEP0_DMA = (uint32_t) ep0_buffer;
USBHSD->UEP0_MAX_LEN = CFG_TUD_ENDPOINT0_SIZE;
xfer_status[0][TUSB_DIR_OUT].max_size = CFG_TUD_ENDPOINT0_SIZE;
xfer_status[0][TUSB_DIR_IN].max_size = CFG_TUD_ENDPOINT0_SIZE;
USBHSD->DEV_AD = 0;
USBHSD->CONTROL |= USBHS_DEV_PU_EN;
@ -180,13 +179,11 @@ void dcd_init(uint8_t rhport) {
void dcd_int_enable(uint8_t rhport) {
(void) rhport;
NVIC_EnableIRQ(USBHS_IRQn);
}
void dcd_int_disable(uint8_t rhport) {
(void) rhport;
NVIC_DisableIRQ(USBHS_IRQn);
}
@ -215,8 +212,7 @@ void dcd_remote_wakeup(uint8_t rhport) {
(void) rhport;
}
void dcd_sof_enable(uint8_t rhport, bool en)
{
void dcd_sof_enable(uint8_t rhport, bool en) {
(void) rhport;
if (en) {
USBHSD->INT_EN |= USBHS_SOF_ACT_EN;
@ -384,7 +380,7 @@ void dcd_int_handler(uint8_t rhport) {
uint16_t rx_len = USBHSD->RX_LEN;
if (ep_num == 0) {
memcpy(&xfer->buffer[xfer->queued_len], ep0_data_in_out_buffer, rx_len);
memcpy(&xfer->buffer[xfer->queued_len], ep0_buffer, rx_len);
}
xfer->queued_len += rx_len;
@ -410,7 +406,7 @@ void dcd_int_handler(uint8_t rhport) {
} else if (int_flag & USBHS_SETUP_FLAG) {
ep_set_response_and_toggle(0x80, EP_RESPONSE_NAK);
ep_set_response_and_toggle(0x00, EP_RESPONSE_NAK);
dcd_event_setup_received(0, ep0_data_in_out_buffer, true);
dcd_event_setup_received(0, ep0_buffer, true);
USBHSD->INT_FG = USBHS_SETUP_FLAG; /* Clear flag */
} else if (int_flag & USBHS_DETECT_FLAG) {