📄 vcomsys.c
字号:
DrvUSB_DataIn(0, (const uint8_t *)psVcomDevice->sProductStringDescriptor, u16Len);
break;
case 3:
u16Len = Minimum(u16Len, gau8StringSerial[0]);
DrvUSB_DataIn(0, gau8StringSerial, u16Len);
break;
default:
// Not support. Reply STALL.
DrvUSB_ClrCtrlReadyAndTrigStall();
}
}
break;
}
default:
// Not support. Reply STALL.
DrvUSB_ClrCtrlReadyAndTrigStall();
}
return;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_SetLineCoding */
/* */
/* Parameters: */
/* pVoid - [in], A pointer to USB class device structure (gsVcomDevice). */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* The callback function when get SET_LINE_CODING request. */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_SetLineCoding(void* pVoid)
{
S_DRVUSB_DEVICE *psDevice = (S_DRVUSB_DEVICE *)((S_VCOM_DEVICE *)pVoid)->device;
DBG_PRINTF("Set line coding\n");
psDevice->abData0[0] = FALSE;
DrvUSB_DataOutTrigger(0, 7);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_SetLineCodingDataOut */
/* */
/* Parameters: */
/* pVoid - [in], A pointer to USB class device structure (gsVcomDevice). */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* The callback function when get the out data of set line coding request. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_SetLineCodingDataOut(void* pVoid)
{
S_DRVUSB_DEVICE *psDevice = (S_DRVUSB_DEVICE *)((S_VCOM_DEVICE *)pVoid)->device;
uint8_t *buf;
uint32_t size;
buf = DrvUSB_GetOutData(0, &size);
memcpy((void *)&gLineCoding, buf, size);
/* ACK to end the transfer */
psDevice->abData0[0] = FALSE;
DrvUSB_DataIn(0, 0, 0);
DBG_PRINTF("Baudrate : %d\n", gLineCoding.u32DTERate);
DBG_PRINTF("Stop bit : %s\n", (gLineCoding.u8CharFormat==2)?"2-bit":((gLineCoding.u8CharFormat)?"1.5-bit":"1-bit"));
{
#ifdef DEBUG
char s[5][6] = {"None", "Odd", "Even", "Mark", "Space"};
#endif
DBG_PRINTF("Parity : %s\n", &s[gLineCoding.u8ParityType][0]);
}
DBG_PRINTF("Data bits: %d\n", gLineCoding.u8DataBits);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_GetLineCoding */
/* */
/* Parameters: */
/* pVoid - [in], A pointer to USB class device structure (gsVcomDevice). */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* The callback function when get GET_LINE_CODING request. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_GetLineCoding(void* pVoid)
{
S_DRVUSB_DEVICE *psDevice = (S_DRVUSB_DEVICE *)((S_VCOM_DEVICE *)pVoid)->device;
psDevice->abData0[0] = TRUE;
DrvUSB_DataIn(0, (void *)&gLineCoding, 7);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_CtrlLineState */
/* */
/* Parameters: */
/* pVoid - [in], A pointer to USB class device structure (gsVcomDevice). */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* The callback function when get SET_CONTROL_LINE_STATE request. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_CtrlLineState(void* pVoid)
{
S_DRVUSB_DEVICE *psDevice = (S_DRVUSB_DEVICE *)((S_VCOM_DEVICE *)pVoid)->device;
gCtrlSignal = psDevice->au8Setup[3];
gCtrlSignal = (gCtrlSignal << 8) | psDevice->au8Setup[2];
DrvUSB_DataIn(0, 0, 0);
DBG_PRINTF("RTS=%d DTR=%d\n", (gCtrlSignal>>1)&1, gCtrlSignal&1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_CtrlSetupSetConfiguration */
/* */
/* Parameters: */
/* pVoid - [in], A pointer to USB class device structure (gsVcomDevice). */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* The callback function when get SET_CONFIGURATION request. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_CtrlSetupSetConfiguration(void* pVoid)
{
S_DRVUSB_DEVICE *pDrvDevice = &gsUsbDevice;
S_DRVUSB_CLASS *psUsbClass = pDrvDevice->psUsbClass;
int32_t bIsDeviceConfigure;
bIsDeviceConfigure = psUsbClass->pfnCompare ? psUsbClass->pfnCompare(pDrvDevice->au8Setup[2]) : 1;
if (pDrvDevice->au8Setup[2] == 0)
{
// USB address state.
DrvUSB_SetUsbState(eDRVUSB_ADDRESS);
pDrvDevice->u8UsbConfiguration = pDrvDevice->au8Setup[2];
DrvUSB_DataIn(0, NULL, 0);
}
else if(bIsDeviceConfigure)
{
// USB configured state.
DrvUSB_SetUsbState(eDRVUSB_CONFIGURED);
// Call USB class's start function
if(psUsbClass->pfnStart)
psUsbClass->pfnStart(pVoid);
pDrvDevice->u8UsbConfiguration = pDrvDevice->au8Setup[2];
DrvUSB_DataIn(0, NULL, 0);
/* Reset bulk in/out endpoint */
DrvUSB_DataOutTrigger(BULK_OUT_EP_NUM, 64);
DrvUSB_DataIn(BULK_IN_EP_NUM, 0, 0);
}
else
{
// Not support. Reply STALL.
DrvUSB_ClrCtrlReadyAndTrigStall();
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_GetVersion */
/* */
/* Parameters: */
/* None */
/* */
/* Returns: */
/* The virtual com driver version number */
/* */
/* Description: */
/* To return the virtual com drvier version number. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t VCOM_GetVersion(void)
{
return VCOM_VERSION_NUM;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_Open */
/* */
/* Parameters: */
/* None */
/* */
/* Returns: */
/* E_SUCCESS */
/* */
/* Description: */
/* To install the virtual com to USB device driver and install the relative descriptors. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
int32_t VCOM_Open(void)
{
S_VCOM_DEVICE *psVcomDevice = &gsVcomDevice;
/* Install the virtual com to USB device */
psVcomDevice->device = (void*)DrvUSB_InstallClassDevice(&sVcomClass);
/* Configure the descritors */
psVcomDevice->au8DeviceDescriptor = gau8DeviceDescriptor;
psVcomDevice->au8ConfigDescriptor = gau8ConfigDescriptor;
psVcomDevice->sVendorStringDescriptor = gau8VendorStringDescriptor;
psVcomDevice->sProductStringDescriptor = gau8ProductStringDescriptor;
/* Install the USB event callbacks */
DrvUSB_InstallCtrlHandler(psVcomDevice->device, g_asCtrlCallbackEntry,
sizeof(g_asCtrlCallbackEntry) / sizeof(g_asCtrlCallbackEntry[0]));
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: VCOM_Close */
/* */
/* Parameters: */
/* None */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* To close virtual com. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void VCOM_Close(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -