📄 camera.cpp
字号:
//RETAILMSG(1, (TEXT("CIS_Init : IOCTL_HAL_REQUEST_SYSINTR \r\n")));
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_CamIrq, sizeof(UINT32), &g_CamSysIntr, sizeof(UINT32), NULL))
{
RETAILMSG(1, (TEXT("ERROR: CIS_INIT: Failed to request sysintr value for Camera interrupt.\r\n")));
return(0);
}
InitializeCriticalSection(&pCIS->RegCS);
RETAILMSG(MSG_EN_1, (TEXT("CIS::InitializeCriticalSection \r\n")));
//
// Init I2C
//
pCIS->hI2C = CreateFile( L"I2C0:",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
if ( INVALID_HANDLE_VALUE == pCIS->hI2C ) {
dwErr = GetLastError();
//DEBUGMSG(ZONE_ERR, (TEXT("Error %d opening device '%s' \r\n"), dwErr, L"I2C0:" ));
RETAILMSG(I2C_MSG, (TEXT("Error %d opening device '%s' \r\n"), dwErr, L"I2C0:" ));
goto _error_exit;
}
RETAILMSG(MSG_EN_1, (TEXT("CIS::CreateFile(\"I2C0\") \r\n")));
//memset((void*)pCIS->eg, 0, sizeof(pCIS->eg));
//
// Gat Fastcall driver-to-driver entrypoints
//
if ( !DeviceIoControl(pCIS->hI2C,
IOCTL_I2C_GET_FASTCALL,
NULL, 0,
&pCIS->fc, sizeof(pCIS->fc),
&bytes, NULL) )
{
dwErr = GetLastError();
DEBUGMSG(ZONE_ERR,(TEXT("IOCTL_I2C_GET_FASTCALL ERROR: %u \r\n"), dwErr));
goto _error_exit;
}
RETAILMSG(MSG_EN_1, (TEXT("CIS::DeviceIoControl \r\n")));
// Init H/W
pCIS->State = INITIALIZE;
Cam_Init();
if (!InitInterruptThread())
{
RETAILMSG(1,(TEXT("Fail to initialize camera interrupt event\r\n")));
return FALSE;
}
pCIS->Dx = D0;
m_Dx = (_CEDEVICE_POWER_STATE)D0;
DevicePowerNotify(_T("CIS1:"),(_CEDEVICE_POWER_STATE)D0, POWER_NAME);
mInitialized = TRUE;
return TRUE;
_error_exit:
return dwErr;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL CIS_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
BOOL RetVal = TRUE;
DWORD dwErr = ERROR_SUCCESS;
static unsigned int time=0,old_time=0;
switch (dwCode)
{
//-----------------------------------------------------------------------------------------
case IOCTL_POWER_CAPABILITIES:
{
PPOWER_CAPABILITIES ppc;
RETAILMSG(1, (TEXT("CIS: IOCTL_POWER_CAPABILITIES\r\n")));
if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(POWER_CAPABILITIES)) ) {
RetVal = FALSE;
dwErr = ERROR_INVALID_PARAMETER;
break;
}
ppc = (PPOWER_CAPABILITIES)pBufOut;
memset(ppc, 0, sizeof(POWER_CAPABILITIES));
// support D0, D4
ppc->DeviceDx = 0x11;
// Report our power consumption in uAmps rather than mWatts.
ppc->Flags = POWER_CAP_PREFIX_MICRO | POWER_CAP_UNIT_AMPS;
// 25 m = 25000 uA
// TODO: find out a more accurate value
ppc->Power[D0] = 25000;
*pdwActualOut = sizeof(POWER_CAPABILITIES);
} break;
case IOCTL_POWER_SET:
{
CEDEVICE_POWER_STATE NewDx;
if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(CEDEVICE_POWER_STATE)) ) {
RetVal = FALSE;
dwErr = ERROR_INVALID_PARAMETER;
break;
}
NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
if ( VALID_DX(NewDx) ) {
switch ( NewDx ) {
case D0:
if (m_Dx != D0) {
CIS_PowerUp(hOpenContext);
m_Dx = D0;
}
break;
default:
if (m_Dx != (_CEDEVICE_POWER_STATE)D4) {
CIS_PowerDown(hOpenContext);
m_Dx = (_CEDEVICE_POWER_STATE)D4;
}
break;
}
// return our state
*(PCEDEVICE_POWER_STATE)pBufOut = m_Dx;
RETAILMSG(1, (TEXT("CIS: IOCTL_POWER_SET: D%u \r\n"), NewDx));
*pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
} else {
RetVal = FALSE;
dwErr = ERROR_INVALID_PARAMETER;
}
} break;
case IOCTL_POWER_GET:
if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(CEDEVICE_POWER_STATE)) ) {
RetVal = FALSE;
dwErr = ERROR_INVALID_PARAMETER;
break;
}
*(PCEDEVICE_POWER_STATE)pBufOut = m_Dx;
RETAILMSG(1, (TEXT("CIS: IOCTL_POWER_GET: D%u \r\n"), m_Dx));
*pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
break;
//-----------------------------------------------------------------------------------------
case IOCTL_CAM_SHOW :
// Charlie. Show Menu
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SHOW(%x)\r\n"),dwLenIn));
break;
case IOCTL_CAM_HIDE :
// Charlie. Close display window
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_HIDE\r\n")));
break;
case IOCTL_CAM_SETPOS :
time = GetTickCount();
// RETAILMSG(MSG_EN_1,(TEXT("Capture time:%d msec\r\n"), (time-old_time)));
RETAILMSG(MSG_EN_1,(TEXT("Capture time:%d msec\r\n"), (time)));
old_time = time;
break;
case CAM_IOCTL_MOVIE_START: // for MPEG4
case IOCTL_CAM_CONT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_CONT(MOVIE_START)\r\n")));
// Charlie. Play
//DisplayEnable = 1;
if (bIdlePwrDown == TRUE)
{
RETAILMSG(PM_MSG, (_T("[CAM_HW] IOControl CAM_START : Turning Codec On\r\n")));
CamInterface_PowerUp();
bIdlePwrDown = FALSE;
}
// Enable camera interrupt
s2440INT->INTMSK &= ~( 1 << IRQ_CAM );
s2440INT->INTSUBMSK &= ~(( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
Camif_Capture(CAPTURE_ON, CAPTURE_ON);
dwDisplayTimeout = DISPLAY_THREAD_TIMEOUT;
//DisplayTime = DISPLAY_THREAD_TIMEOUT; // polling mode
//SetEvent(CameraEvent);
//s2440IOP->GPGCON &= ~(0x3<<24);
//s2440IOP->GPGCON |= (0x1<<24); // EINT20
frame_count = 0; // for MPEG4
break;
case CAM_IOCTL_MOVIE_STOP: // for MPEG4
case IOCTL_CAM_STOP :
// Charlie. Stop
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_STOP\r\n")));
// Disable camera interrupt
s2440INT->INTMSK |= ( 1 << IRQ_CAM );
s2440INT->INTSUBMSK |= (( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
if (s2440INT->INTPND & ( 1 << IRQ_CAM )) s2440INT->INTPND |= ( 1 << IRQ_CAM );
s2440INT->SRCPND |= ( 1 << IRQ_CAM );
s2440INT->SUBSRCPND |= (( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
/*
s2440CAM->CICOCTRL |= (1<<2); // CODEC Last IRQ Enable
s2440CAM->CIPRCTRL |= (1<<2); // PREVIEW Last IRQ Enable
*/
Camif_Capture(CAPTURE_OFF, CAPTURE_OFF);
//DisplayEnable = 0;
// 2004.05.18 jylee
DRIVER_PREVIEW_ENABLE = 2;
//dwDisplayTimeout = INFINITE;
break;
// for MPEG4
case CAM_IOCTL_GET_LATEST_FRAME:
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:CAM_IOCTL_GET_LATEST_FRAME\r\n")));
//RETAILMSG(MSG_EN_1,(TEXT("pBufIn = 0x%x\r\n"), pBufIn));
//RETAILMSG(MSG_EN_1,(TEXT("no function available, TBD\r\n")));
if (frame_count < 2) {
RETAILMSG(1,(TEXT("CAMERA:CAM_IOCTL_GET_LATEST_FRAME - frame not available!!!\r\n")));
return FALSE;
}
Tick_GET_FRAME_PREV = Tick_GET_FRAME_CUR;
Tick_GET_FRAME_CUR = GetTickCount();
Copy_Cam_Image(pBufOut, QCIF_XSIZE, QCIF_YSIZE, PORT_A);
break;
case CAM_IOCTL_SAMSUNG_CAM: // ID=0x520
RETAILMSG(MSG_EN_1,(_T("CAM_IOCTL_SAMSUNG_CAM\r\n")));
Samsung_camcoder(pBufOut);
break;
case CAM_IOCTL_SAMSUNG_CAM_PR: // ID=0x522
RETAILMSG(MSG_EN_1,(_T("CAM_IOCTL_SAMSUNG_CAM_PR\r\n")));
Samsung_camcoder_pr(pBufOut);
break;
case CAM_IOCTL_SAMSUNG_PREVIEW_START : // ID=0x523
DRIVER_PREVIEW_ENABLE = 1;
RETAILMSG(MSG_EN_1,(_T("CAM_IOCTL_SAMSUNG_PREVIEW_START(%x)\r\n"),*pBufOut, DRIVER_PREVIEW_ENABLE));
break;
case CAM_IOCTL_SAMSUNG_PREVIEW_STOP : // ID=0x524
DRIVER_PREVIEW_ENABLE = 2;
RETAILMSG(MSG_EN_1,(_T("CAM_IOCTL_SAMSUNG_PREVIEW_STOP(%x)\r\n"),*pBufOut, DRIVER_PREVIEW_ENABLE));
break;
case IOCTL_CAM_SETGAMMA :
if( *pBufOut == 1 ){
DRIVER_PREVIEW_ENABLE = 1;
}
else if( *pBufOut == 2 ){
DRIVER_PREVIEW_ENABLE = 2;
}
RETAILMSG(MSG_EN_1,(_T("IOCTL_CAM_SETGAMMA:*pBufOut(%x):DRIVER_PREVIEW_ENABLE(%x)\r\n"),*pBufOut, DRIVER_PREVIEW_ENABLE));
break;
/*
case CAM_IOCTL_IMAGE_SIZE: // ID=0x521
RETAILMSG(MSG_EN_1,(TEXT("CAM_IOCTL_IMAGE_SIZE\r\n")));
if (bIdlePwrDown == TRUE)
{
RETAILMSG(PM_MSG, (_T("[CAM_HW] IOControl CAM_START : Turning Codec On\r\n")));
CamInterface_PowerUp();
bIdlePwrDown = FALSE;
}
if( *pBufOut == 1 ){
image_size = 1;
}
else if( *pBufOut == 2 ){
image_size = 2;
}
RETAILMSG(MSG_EN_1,(TEXT("image_size:%d,0x%x,0x%x\r\n"),image_size,pBufOut,*pBufOut));
s2440INT->INTMSK |= ( 1 << IRQ_CAM );
s2440INT->INTSUBMSK |= (( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
Camif_Capture(CAPTURE_OFF, CAPTURE_OFF);
if (image_size == 1)
CamInit(QCIF_XSIZE, QCIF_YSIZE, QCIF_XSIZE, QCIF_YSIZE, 120, 100, COPIFRAMEBUFFER_B, COPIFRAMEBUFFER_A);
else if (image_size == 2)
CamInit(CIF_XSIZE, CIF_YSIZE, QCIF_XSIZE, QCIF_YSIZE, 120, 100, COPIFRAMEBUFFER_B, COPIFRAMEBUFFER_A);
break;
*/
case CAM_IOCTL_IMAGE_CHANGE: // ID=0x521
RETAILMSG(MSG_EN_1,(TEXT("CAM_IOCTL_IMAGE_CHANGE\r\n")));
if (bIdlePwrDown == TRUE)
{
RETAILMSG(PM_MSG, (_T("[CAM_HW] IOControl CAM_START : Turning Codec On\r\n")));
CamInterface_PowerUp();
bIdlePwrDown = FALSE;
}
memcpy(&sCAMINFO, pBufOut, sizeof(sCAMINFO));
RETAILMSG(MSG_EN_1,(TEXT("image_Xsize:%d, image_YSize:%d, ZoomIndex:%d\r\n"), sCAMINFO.nDestWidth, sCAMINFO.nDestHeight, sCAMINFO.nZoomIndex));
s2440INT->INTMSK |= ( 1 << IRQ_CAM );
s2440INT->INTSUBMSK |= (( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
Camif_Capture(CAPTURE_OFF, CAPTURE_OFF);
if((sCAMINFO.nZoomIndex == 2) ||(sCAMINFO.nZoomIndex == 3))
CamInit(sCAMINFO.nDestWidth, sCAMINFO.nDestHeight, PREVIEW_X, PREVIEW_Y, sCAMINFO.nZoomIndex*80, sCAMINFO.nZoomIndex*60, (U32)(g_PhysCodecAddr.LowPart), (U32)(g_PhysPreviewAddr.LowPart));
else if(sCAMINFO.nZoomIndex == 1)
CamInit(sCAMINFO.nDestWidth, sCAMINFO.nDestHeight, PREVIEW_X, PREVIEW_Y, 120, 100, (U32)(g_PhysCodecAddr.LowPart), (U32)(g_PhysPreviewAddr.LowPart));
else
CamInit(CIF_XSIZE, CIF_YSIZE, PREVIEW_X, PREVIEW_Y, 120, 100, (U32)(g_PhysCodecAddr.LowPart), (U32)(g_PhysPreviewAddr.LowPart));
break;
case IOCTL_CAM_COPY :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_COPY(dwLenIn:%x)\r\n"), dwLenIn));
break;
case IOCTL_CAM_SETCOLKEY :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETCOLKEY\r\n")));
break;
case IOCTL_CAM_SETALPHA :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETALPHA\r\n")));
break;
case IOCTL_CAM_GETINFO :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_GETINFO\r\n")));
break;
case IOCTL_CAM_SETSCALE :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETSCALE\r\n")));
break;
case IOCTL_CAM_SETHUE :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETHUE\r\n")));
break;
#if 0
case IOCTL_CAM_SETGAMMA :
// Get which ping -pong buffer have data
//DisplayEnable = 0;
Sleep(200);
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_BUFFER:%d\r\n"),buffer_num));
break;
#endif
case IOCTL_CAM_SETWBCOORD :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETWBCOORD\r\n")));
break;
case IOCTL_CAM_SETAELIMIT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETAELIMIT\r\n")));
break;
case IOCTL_CAM_SETADCOFS :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETADCOFS\r\n")));
break;
case IOCTL_CAM_SETWBGAIN :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETWBGAIN\r\n")));
break;
case IOCTL_CAM_SETCBCRGAIN :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETCBCRGAIN\r\n")));
break;
case IOCTL_CAM_SETLEGAIN :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETLEGAIN\r\n")));
break;
case IOCTL_CAM_SETBRIGHTNESS :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETBRIGHTNESS\r\n")));
break;
case IOCTL_CAM_SETCLIP :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETCLIP\r\n")));
break;
case IOCTL_CAM_SETSLICELMT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETSLICELMT\r\n")));
break;
case IOCTL_CAM_WBACCLMT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_WBACCLMT\r\n")));
break;
case IOCTL_CAM_CSEDGELMT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_CSEDGELMT\r\n")));
break;
case IOCTL_CAM_ENVINT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_ENVINT\r\n")));
break;
case IOCTL_CAM_DISVINT :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_DISVINT\r\n")));
break;
case IOCTL_CAM_SETCAMERA :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:IOCTL_CAM_SETCAMERA\r\n")));
/*
RETAILMSG(MSG_EN_1,(_T("---------------------------------------\r\n")));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn_PRSC = %d\r\n"), (s2440CAM->CIPRSTATUS>>21)&0x1));
RETAILMSG(MSG_EN_1,(_T("PrScalerStart = %d\r\n"), (s2440CAM->CIPRSCCTRL>>15)&0x1));
RETAILMSG(MSG_EN_1,(_T("---------------------------------------\r\n")));
RETAILMSG(MSG_EN_1,(_T("CoScalerStart = %d\r\n"), (s2440CAM->CICOSCCTRL>>15)&0x1));
RETAILMSG(MSG_EN_1,(_T("VSYNC = %d\r\n"), (s2440CAM->CICOSTATUS>>28)&0x1));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn_Camif = %d\r\n"), (s2440CAM->CICOSTATUS>>22)&0x1));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn_CoSC = %d\r\n"), (s2440CAM->CICOSTATUS>>21)&0x1));
RETAILMSG(MSG_EN_1,(_T("VSYNC_A = %d\r\n"), (s2440CAM->CICOSTATUS>>20)&0x1));
RETAILMSG(MSG_EN_1,(_T("VSYNC_B = %d\r\n"), (s2440CAM->CICOSTATUS>>19)&0x1));
RETAILMSG(MSG_EN_1,(_T("---------------------------------------\r\n")));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn = %d\r\n"), (s2440CAM->CIIMGCPT>>31)&0x1));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn_CoSc = %d\r\n"), (s2440CAM->CIIMGCPT>>30)&0x1));
RETAILMSG(MSG_EN_1,(_T("ImgCptEn_PrSc = %d\r\n"), (s2440CAM->CIIMGCPT>>29)&0x1));
RETAILMSG(MSG_EN_1,(_T("----------------- %d ----------------------\r\n"), mInitialized));
SetEvent(CameraEvent);
*/
break;
default :
RETAILMSG(MSG_EN_1,(TEXT("CAMERA:Ioctl code = 0x%x\r\n"), dwCode));
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
DWORD CIS_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
RETAILMSG(1,(TEXT("CAMERA: CIS_Open\r\n")));
DRIVER_PREVIEW_ENABLE = 2;
return TRUE;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL CIS_Close(DWORD hOpenContext)
{
RETAILMSG(1,(TEXT("CAMERA: CIS_Close\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CIS_PowerDown(DWORD hDeviceContext)
{
RETAILMSG(1,(TEXT("CAMERA: CIS_PowerDown\r\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -