display_main.cpp
来自「6410BSP3」· C++ 代码 · 共 1,962 行 · 第 1/5 页
CPP
1,962 行
m_hVideoDrv = CreateFile( L"VDE0:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (m_hVideoDrv == INVALID_HANDLE_VALUE)
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] AllocResource() : VDE0 Open Device Failed\n\r")));
return FALSE;
}
// Request FIMD H/W Resource to Video Engine Driver
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] DevInitialize() : IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE Failed\n\r")));
return FALSE;
}
// Request FIMD Win1 H/W Resource to Video Engine Driver for Primary Window
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_REQUEST_FIMD_WIN1, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] DevInitialize() : IOCTL_SVE_RSC_REQUEST_FIMD_WIN1 Failed\n\r")));
return FALSE;
}
// Frame Buffer
m_VideoMemoryPhysicalBase = IMAGE_FRAMEBUFFER_PA_START;
m_VideoMemorySize = IMAGE_FRAMEBUFFER_SIZE;
m_VideoMemoryVirtualBase = (DWORD)VirtualAlloc(NULL, m_VideoMemorySize, MEM_RESERVE, PAGE_NOACCESS);
if (NULL == VirtualCopy((void *)m_VideoMemoryVirtualBase, (void *)(m_VideoMemoryPhysicalBase>>8), m_VideoMemorySize, PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL))
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] AllocResource() : m_VideoMemoryVirtualBase VirtualCopy() Failed : %x\n\r"), GetLastError()));
return FALSE;
}
#if 1
// Platform Independent
if(CeSetMemoryAttributes((void *)m_VideoMemoryVirtualBase, (void *)(m_VideoMemoryPhysicalBase>>8), m_VideoMemorySize, PAGE_WRITECOMBINE) != TRUE)
{
RETAILMSG(DISP_ZONE_WARNING, (_T("[DISPDRV:ERR] AllocResource() : m_VideoMemoryVirtualBase CeSetMemoryAttributes() Failed : %x\n\r"), GetLastError()));
}
#else
// Platform Dependent, change TLB directly, as NonCachable and Bufferable attributes for ARM9, Shared Device attribute for ARM11 and Cortex
if(VirtualSetAttributes((void *)m_VideoMemoryVirtualBase, m_VideoMemorySize, 0x4, 0xc, NULL) != TRUE)
{
RETAILMSG(DISP_ZONE_WARNING, (_T("[DISPDRV:ERR] AllocResource() : m_VideoMemoryVirtualBase VirtualSetAttributes() Failed : %x\n\r"), GetLastError()));
}
#endif
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV:INF] m_VideoMemoryPhysicalBase = 0x%08x\n\r"), m_VideoMemoryPhysicalBase));
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV:INF] m_VideoMemoryVirtualBase = 0x%08x\n\r"), m_VideoMemoryVirtualBase));
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV:INF] m_VideoMemorySize = 0x%08x\n\r"), m_VideoMemorySize));
// Allocate SurfaceHeap
m_pVideoMemoryHeap = new SurfaceHeap(m_VideoMemorySize, m_VideoMemoryVirtualBase, NULL, NULL);
if(!m_pVideoMemoryHeap)
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] %s : SurfaceHeap() allocate Fail\n\r"),_T(__FUNCTION__)));
return FALSE;
}
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s\n\r"), _T(__FUNCTION__)));
return TRUE;
CleanUp:
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] --%s : Failed, ioPhysicalBase(0x%x,0x%x)\r\n"), _T(__FUNCTION__), ioPhysicalBase.LowPart, ioPhysicalBase.HighPart));
return FALSE;
}
void
S3C6410Disp::ReleaseResource(void)
{
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));
DWORD dwBytes;
if (m_pVideoMemoryHeap != NULL)
{
delete m_pVideoMemoryHeap;
}
if (m_VideoMemoryVirtualBase != NULL)
{
VirtualFree((LPVOID)m_VideoMemoryVirtualBase, 0, MEM_RELEASE);
}
if (m_pDispConReg != NULL)
{
MmUnmapIoSpace((PVOID)m_pDispConReg, sizeof(S3C6410_DISPLAY_REG));
m_pDispConReg = NULL;
}
if (m_pGPIOReg != NULL)
{
MmUnmapIoSpace((PVOID)m_pGPIOReg, sizeof(S3C6410_GPIO_REG));
m_pGPIOReg = NULL;
}
if (m_pSPIReg != NULL)
{
MmUnmapIoSpace((PVOID)m_pSPIReg, sizeof(S3C6410_SPI_REG));
m_pSPIReg = NULL;
}
// Release FIMD Win1 H/W Resource to Video Engine Driver for Primary Window
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_RELEASE_FIMD_WIN1, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] ReleaseResource() : IOCTL_SVE_RSC_RELEASE_FIMD_WIN1 Failed\n\r")));
}
// Release FIMD H/W Resource to Video Engine Driver
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_RELEASE_FIMD_INTERFACE, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] ReleaseResource() : IOCTL_SVE_RSC_RELEASE_FIMD_INTERFACE Failed\n\r")));
}
// Close Video Engine Driver
if (m_hVideoDrv!= INVALID_HANDLE_VALUE)
{
CloseHandle(m_hVideoDrv);
m_hVideoDrv = INVALID_HANDLE_VALUE;
}
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
}
BOOL
S3C6410Disp::TVOutAllocResource(void)
{
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));
BOOL bRet = TRUE;
DWORD dwBytes;
// Request TV Scaler & TV Encoder H/W Resource to Video Engine Driver for TV Out
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_REQUEST_TVSCALER_TVENCODER, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] TVOutAllocResource() : IOCTL_SVE_RSC_REQUEST_TVSCALER_TVENCODER Failed\n\r")));
bRet = FALSE;
}
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
return bRet;
}
BOOL
S3C6410Disp::TVOutReleaseResource(void)
{
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));
BOOL bRet = TRUE;
DWORD dwBytes;
// Release TV Scaler & TV Encoder H/W Resource to Video Engine Driver
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_RSC_RELEASE_TVSCALER_TVENCODER, NULL, 0, NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] TVOutReleaseResource() : IOCTL_SVE_RSC_RELEASE_TVSCALER_TVENCODER Failed\n\r")));
bRet = FALSE;
}
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
return bRet;
}
// returns DD_OK for OK otherwise error code
// populates *pFormat, and *pPixelFormat
SCODE
S3C6410Disp::DetectPixelFormat(
DWORD dwCaps, // in: DDSCAPS_xxx flags
DDPIXELFORMAT* pDDPF, // in: Explicit pixel format or current mode
EGPEFormat* pFormat,
EDDGPEPixelFormat* pPixelFormat
)
{
SCODE rv = DDGPE::DetectPixelFormat(dwCaps, pDDPF, pFormat, pPixelFormat);
if (rv == DDERR_UNSUPPORTEDFORMAT)
{
if(pDDPF->dwFlags & DDPF_FOURCC)
{
if( pDDPF->dwFourCC == FOURCC_I420 )
{
*pPixelFormat = (EDDGPEPixelFormat)ddgpePixelFormat_I420;
*pFormat = gpe16Bpp; // 12Bpp is not defined in GPE
return DD_OK;
}
else if( pDDPF->dwFourCC == FOURCC_YVYU )
{
*pPixelFormat = (EDDGPEPixelFormat)ddgpePixelFormat_YVYU;
*pFormat = gpe16Bpp;
return DD_OK;
}
else if( pDDPF->dwFourCC == FOURCC_VYUY )
{
*pPixelFormat = (EDDGPEPixelFormat)ddgpePixelFormat_VYUY;
*pFormat = gpe16Bpp;
return DD_OK;
}
}
return DDERR_UNSUPPORTEDFORMAT;
}
else
{
return rv;
}
}
void
S3C6410Disp::SetDisplayPowerState(VIDEO_POWER_STATE PowerState)
{
static BYTE * pVideoMemory = NULL;
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s(%d)\n\r"), _T(__FUNCTION__), PowerState));
// If we're already in the appropriate state, just return
if (m_VideoPowerState == PowerState)
{
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV] SetDisplayPowerState() : Same as current State [%d]\n\r"), m_VideoPowerState));
return;
}
if (PowerState == VideoPowerOn)
{
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV] SetDisplayPowerState() : VideoPowerOn\n\r")));
if (m_VideoPowerState == VideoPowerOn)
{
// Do Nothing
}
else // from VideoPowerOff or VideoPowerSuspend
{
DevPowerOn();
DynRotate(m_iRotate);
m_CursorDisabled = FALSE;
//CursorOn(); // in DynRotate()
//m_CursorVisible = TRUE; // in CursorOn()
}
m_VideoPowerState = VideoPowerOn;
}
else if (PowerState == VideoPowerOff)
{
RETAILMSG(DISP_ZONE_TEMP, (_T("[DISPDRV] SetDisplayPowerState() : VideoPowerOff\n\r")));
if (m_VideoPowerState == VideoPowerOff)
{
// Do Nothing
}
else // from VideoPowerOn or VideoPowerStandby
{
m_CursorDisabled = TRUE;
CursorOff();
// Turn Off Display Controller
DevPowerOff();
}
m_VideoPowerState = VideoPowerOff;
}
}
VIDEO_POWER_STATE
S3C6410Disp::GetDisplayPowerState(void)
{
return m_VideoPowerState;
}
BOOL
S3C6410Disp::WaitForVerticalBlank(VB_STATUS Status)
{
BOOL bRet = FALSE;
bRet = DevWaitForVerticalBlank();
return bRet;
}
DWORD
S3C6410Disp::GetScanLine(void)
{
DWORD dwRet = 0;
dwRet = DevGetScanLine();
return dwRet;
}
BOOL
S3C6410Disp::DevInitialize(void)
{
SVEARG_FIMD_OUTPUT_IF tParam;
DWORD dwBytes;
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));
EnterCriticalSection(&m_csDevice);
// Initialize SFR Address of Sub Module
LDI_initialize_register_address((void *)m_pSPIReg, (void *)m_pDispConReg, (void *)m_pGPIOReg);
// Set LCD Module Type
#if (SMDK6410_LCD_MODULE == LCD_MODULE_LTS222)
LDI_set_LCD_module_type(LDI_LTS222QV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_LTV350)
LDI_set_LCD_module_type(LDI_LTV350QV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_LTE480)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_EMUL48_D1)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_EMUL48_QV)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_EMUL48_PQV)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_EMUL48_ML)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_EMUL48_MP)
LDI_set_LCD_module_type(LDI_LTE480WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_LTP700)
LDI_set_LCD_module_type(LDI_LTP700WV_RGB);
#elif (SMDK6410_LCD_MODULE == LCD_MODULE_LTM030DK)
LDI_set_LCD_module_type(LDI_LTM030DK_RGB);
#endif
// Get RGB Interface Information from LDI Library
LDI_fill_output_device_information(&tParam.tRGBDevInfo);
tParam.dwTVOutScreenWidth = m_dwDeviceScreenWidth;
tParam.dwTVOutScreenHeight = m_dwDeviceScreenHeight;
// Initialize Display Interface Parameter
if ( !DeviceIoControl(m_hVideoDrv, IOCTL_SVE_FIMD_SET_INTERFACE_PARAM, &tParam, sizeof(SVEARG_FIMD_OUTPUT_IF), NULL, 0, &dwBytes, NULL) )
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] DevInitialize() : IOCTL_SVE_FIMD_SET_INTERFACE_PARAM Failed\n\r")));
}
// Check TV Scaler Limitation
if ((m_eOutputInterface == OUTPUT_IF_TV) && (m_dwDeviceScreenWidth > 800))
{
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] DevInitialize() : For TVout, Screen width[%d] should be lower than 800 pixel\n\r"), m_dwDeviceScreenWidth));
RETAILMSG(DISP_ZONE_ERROR, (_T("[DISPDRV:ERR] DevInitialize() : Output Interface forced to RGB I/F\n\r")));
m_eOutputInterface = OUTPUT_IF_RGB;
}
if (m_eOutputInterface == OUTPUT_IF_RGB)
{
DevOutputEnableRGBIF();
}
else if (m_eOutputInterface == OUTPUT_IF_TV)
{
// Backlight Off
DevicePowerNotify(_T("BKL1:"),(_CEDEVICE_POWER_STATE)D4, POWER_NAME);
DevOutputEnableTV();
}
LeaveCriticalSection(&m_csDevice);
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] --%s()\n\r"), _T(__FUNCTION__)));
return TRUE;
}
BOOL
S3C6410Disp::DevPowerOn(void)
{
DWORD dwBytes;
RETAILMSG(DISP_ZONE_ENTER, (_T("[DISPDRV] ++%s()\n\r"), _T(__FUNCTION__)));
EnterCriticalSection(&m_csDevice);
#if (SMDK6410_LCD_MODULE == LCD_MODULE_LTM030DK)
LDI_LTM030DK_SetALC();
#endif
#if ((SMDK6410_LCD_MODULE == LCD_MODULE_LTS222) \
|| (SMDK6410_LCD_MODULE == LCD_MODULE_LTV350) \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?