📄 uvcsys.c
字号:
/* */
/* INPUTS */
/* None */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* The UVC driver version. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t UVC_GetVersion(void)
{
return UVC_VERSION_NUM;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_GetIsoOutPackeSize() */
/* */
/* DESCRIPTION */
/* To get the ISO OUT packet size according configuration descriptor. */
/* */
/* INPUTS */
/* u8Cfg The pointer of configuration descriptor. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* The packet size of ISO OUT. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
uint16_t UVC_GetIsoOutPackeSize(const uint8_t *u8Cfg)
{
uint16_t packetSize;
int32_t offset;
offset = 0;
while(1)
{
offset += u8Cfg[offset];
/* Limit the max search size */
if (offset > LEN_CONFIG_AND_SUBORDINATE)
break;
if ((u8Cfg[offset + 1] == 0x05) && (u8Cfg[offset + 3] == 0x0D))
{
packetSize = u8Cfg[offset + 4] | ((uint16_t)u8Cfg[offset + 5] << 8);
return packetSize;
}
}
return 0;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_Open() */
/* */
/* DESCRIPTION */
/* To initial all descriptors and control handlers of USB Video Class. */
/* */
/* INPUTS */
/* pVoid The function point of UVC device */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
int32_t UVC_Open(void * pVoid)
{
g_UVC_sDevice.device = (void *)DrvUSB_InstallClassDevice(&sUvcUsbClass);
g_UVC_sDevice.u8IsoOutPacketSize = UVC_GetIsoOutPackeSize(gau8ConfigDescriptor);
g_UVC_sDevice.i16RecMaxVolume = 6144; /* about 24dB */
g_UVC_sDevice.i16RecMinVolume = -32767; /* about -128dB */
g_UVC_sDevice.i16RecResVolume = 256; /* 1dB step */
g_UVC_sDevice.i16PlayMaxVolume = 768; /* about 3dB */
g_UVC_sDevice.i16PlayMinVolume = -8191; /* about -32dB */
g_UVC_sDevice.i16PlayResVolume = 256; /* 1dB step */
DrvUSB_InstallCtrlHandler(g_UVC_sDevice.device, g_asCtrlCallbackEntry,
sizeof(g_asCtrlCallbackEntry) / sizeof(g_asCtrlCallbackEntry[0]));
DrvUSB_EnableSelfPower();
DrvUSB_DisableRemoteWakeup();
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_Close() */
/* */
/* DESCRIPTION */
/* None. */
/* */
/* INPUTS */
/* None */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UVC_Close(void)
{
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_Reset() */
/* */
/* DESCRIPTION */
/* The function to reset endpoint settings. It would be called at set configuration or set interface. */
/* */
/* INPUTS */
/* psDevice The function point of UVC device */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UVC_Reset(void * *pVoid)
{
uint32_t u32EpId;
S_UVC_DEVICE *psDevice = (S_UVC_DEVICE *)pVoid;
S_DRVUSB_DEVICE *psUsbDevice;
psUsbDevice = (S_DRVUSB_DEVICE *)psDevice->device;
/* Reset ISO IN endpoint setting */
u32EpId = DrvUSB_GetEpIdentity(ISO_IN_EP_NUM, EP_INPUT);
_DRVUSB_SET_CFG(u32EpId, CFG_ISO_IN);
_DRVUSB_SET_CFGP(u32EpId, CFGP_CLRRDY);
_DRVUSB_SET_EP_BUF(u32EpId, (uint32_t)psUsbDevice->sEpCrl[u32EpId].u8SramBuffer);
/* Reset ISO OUT endpoint setting */
u32EpId = DrvUSB_GetEpIdentity(ISO_OUT_EP_NUM, EP_OUTPUT);
_DRVUSB_SET_CFG(u32EpId, CFG_ISO_OUT);
_DRVUSB_SET_CFGP(u32EpId, CFGP_CLRRDY);
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_IsCfgId() */
/* */
/* DESCRIPTION */
/* To check if it is the specified bConfigurationValue in the confiuration descriptor. */
/* */
/* INPUTS */
/* u8ConfigureValue The bConfigurationValue to check. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* E_SUCCESS */
/* */
/*---------------------------------------------------------------------------------------------------------*/
int32_t UVC_IsCfgId(uint8_t u8ConfiguationValue)
{
return (u8ConfiguationValue == gau8ConfigDescriptor[5]);
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_SendOnePacket() */
/* */
/* DESCRIPTION */
/* Send one packet to host. */
/* */
/* INPUTS */
/* pbyData The data buffer pointer. */
/* u8DataSize The data size in byte. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* None */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UVC_SendOnePacket(uint8_t *pbyData, uint8_t u8DataSize)
{
if (u8DataSize > 0)
{
DrvUSB_DataIn(ISO_IN_EP_NUM, (uint8_t *)pbyData, u8DataSize);
}
else
{
_DRVUSB_TRIG_EP(DrvUSB_GetEpIdentity(ISO_IN_EP_NUM, EP_INPUT), 0);
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* FUNCTION */
/* UVC_Init() */
/* */
/* DESCRIPTION */
/* Install the callback functions for device enable, disable, ISO IN and ISO OUT. */
/* */
/* INPUTS */
/* pfnDeviceEnable The callback function to enable video device. */
/* pfnDeviceDisable The callback function to disable video device. */
/* pfnSendData The callback function to prepare the data for ISO IN. */
/* pfnGetPlayData The callback function to get ISO OUT data. */
/* */
/* OUTPUTS */
/* None */
/* */
/* RETURN */
/* None */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void UVC_Init(
UVC_DEVICE_ENABLE pfnDeviceEnable,
UVC_DEVICE_DISABLE pfnDeviceDisable,
UVC_ISO_IN pfnSendData,
UVC_ISO_OUT pfnGetPlayData
)
{
pfnUvcDeviceEnable = pfnDeviceEnable;
pfnUvcDeviceDisable = pfnDeviceDisable;
pfnUvcSendData = pfnSendData;
pfnUvcGetPlayData = pfnGetPlayData;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -