mirror of
https://github.com/XIVN1987/DAPLink.git
synced 2026-09-26 22:16:11 +00:00
simplify VCOM code
This commit is contained in:
Binary file not shown.
+1512
-1514
File diff suppressed because it is too large
Load Diff
@@ -214,15 +214,12 @@ void EP2_IN_Callback(void)
|
||||
|
||||
void EP3_IN_Callback(void)
|
||||
{
|
||||
Vcom.in_ready = 1;
|
||||
}
|
||||
|
||||
|
||||
void EP3_OUT_Callback(void)
|
||||
{
|
||||
Vcom.out_bytes = USB_SIL_Read(EP3_OUT, (uint8_t *)Vcom.out_buff);
|
||||
|
||||
Vcom.out_ready = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -259,8 +259,6 @@ void USBD_Reset(void)
|
||||
SetDeviceAddress(0);
|
||||
|
||||
bDeviceState = ATTACHED;
|
||||
|
||||
Vcom.in_ready = 1;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
@@ -127,7 +127,7 @@ void VCOM_TransferData(void)
|
||||
static uint32_t last_ms = 0;
|
||||
static uint32_t last_pos = 0;
|
||||
|
||||
if(Vcom.in_ready) // 可以向主机发送数据
|
||||
if(GetEPTxStatus(ENDP3) == EP_TX_NAK) // 可以向主机发送数据
|
||||
{
|
||||
uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel6);
|
||||
if((pos - last_pos >= CDC_BULK_IN_SZ) || ((pos != last_pos) && (SysTick_ms != last_ms)))
|
||||
@@ -140,8 +140,6 @@ void VCOM_TransferData(void)
|
||||
|
||||
Vcom.in_bytes = pos - last_pos;
|
||||
|
||||
Vcom.in_ready = 0;
|
||||
|
||||
USB_SIL_Write(EP3_IN, &RXBuffer[last_pos], Vcom.in_bytes);
|
||||
SetEPTxValid(ENDP3);
|
||||
|
||||
@@ -164,16 +162,16 @@ void VCOM_TransferData(void)
|
||||
}
|
||||
|
||||
/* 从主机接收到数据,且前面的数据 DMA 已发送完 */
|
||||
if(Vcom.out_ready && (DMA_GetCurrDataCounter(DMA1_Channel7) == 0))
|
||||
if(Vcom.out_bytes && (DMA_GetCurrDataCounter(DMA1_Channel7) == 0))
|
||||
{
|
||||
Vcom.out_ready = 0;
|
||||
|
||||
memcpy(TXBuffer, (uint8_t *)Vcom.out_buff, Vcom.out_bytes);
|
||||
|
||||
DMA_Cmd(DMA1_Channel7, DISABLE);
|
||||
DMA_SetCurrDataCounter(DMA1_Channel7, Vcom.out_bytes);
|
||||
DMA_Cmd(DMA1_Channel7, ENABLE);
|
||||
|
||||
Vcom.out_bytes = 0;
|
||||
|
||||
/* Ready for next BULK OUT */
|
||||
SetEPRxValid(ENDP3);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@ typedef struct {
|
||||
|
||||
uint8_t in_buff[64];
|
||||
uint16_t in_bytes;
|
||||
uint16_t in_ready;
|
||||
uint8_t out_buff[64];
|
||||
uint16_t out_bytes;
|
||||
uint16_t out_ready;
|
||||
} VCOM;
|
||||
|
||||
extern volatile VCOM Vcom;
|
||||
|
||||
Reference in New Issue
Block a user