s3c24a0disp.cpp
来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C++ 代码 · 共 1,374 行 · 第 1/3 页
CPP
1,374 行
return S_OK;
}
INT S3C24A0DISP::InVBlank(void)
{
#ifdef DD_ENABLE
static BOOL value = FALSE;
RETAILMSG(DBGLCD, (TEXT("S3C24A0DISP::InVBlank\r\n")));
value = !value;
return value;
#else
return 0;
#endif
}
SCODE S3C24A0DISP::SetPalette(const PALETTEENTRY *source, USHORT firstEntry, USHORT numEntries)
{
RETAILMSG(DBGLCD, (TEXT("S3C24A0DISP::SetPalette\r\n")));
if (firstEntry < 0 || firstEntry + numEntries > 256 || source == NULL)
{
return E_INVALIDARG;
}
return S_OK;
}
VIDEO_POWER_STATE
PmToVideoPowerState(CEDEVICE_POWER_STATE pmDx)
{
VIDEO_POWER_STATE vps;
switch(pmDx) {
case D0: // turn the display on
vps = VideoPowerOn;
break;
case D1: // if asked for a state we don't support, go to the next lower one
case D2:
case D3:
case D4:
vps = VideoPowerOff;
break;
default:
RETAILMSG(1 , (L"PmToVideoPowerState: mapping unknown PM state %d to VideoPowerOn\r\n", pmDx));
vps = VideoPowerOn;
break;
}
return vps;
}
// this routine maps video power states to PM power states.
CEDEVICE_POWER_STATE
VideoToPmPowerState(VIDEO_POWER_STATE vps)
{
CEDEVICE_POWER_STATE pmDx;
switch(vps)
{
case VideoPowerOn:
pmDx = D0;
break;
case VideoPowerStandBy:
pmDx = D1;
break;
case VideoPowerSuspend:
pmDx = (CEDEVICE_POWER_STATE)D2;
break;
case VideoPowerOff:
pmDx = (CEDEVICE_POWER_STATE)D4;
break;
default:
pmDx = D0;
RETAILMSG(1, (L"VideoToPmPowerState: mapping unknown video state %d to pm state %d\r\n",
vps, pmDx));
break;
}
return pmDx;
}
#define ESC_SUCCESS 0x00000001
#define ESC_FAILED 0xFFFFFFFF
#define ESC_NOT_SUPPORTED 0x00000000
ULONG S3C24A0DISP::DrvEscape(
SURFOBJ *pso,
ULONG iEsc,
ULONG cjIn,
PVOID pvIn,
ULONG cjOut,
PVOID pvOut)
{
ULONG Result = 0;
LPWSTR pszFname = L"S3C24A0LCD::DrvEscape";
switch (iEsc)
{
case QUERYESCSUPPORT:
if (sizeof (DWORD) == cjIn)
{
DWORD SupportChk;
SupportChk = *(DWORD *)pvIn;
if ((SupportChk == QUERYESCSUPPORT) ||
(SupportChk == GETPOWERMANAGEMENT) ||
(SupportChk == SETPOWERMANAGEMENT) ||
(SupportChk == IOCTL_POWER_CAPABILITIES) ||
(SupportChk == IOCTL_POWER_QUERY) ||
(SupportChk == IOCTL_POWER_SET) ||
(SupportChk == IOCTL_POWER_GET))
{
Result = ESC_SUCCESS;
}
else
{
Result = ESC_NOT_SUPPORTED;
}
}
else
{
SetLastError(ERROR_INVALID_PARAMETER);
Result = ESC_FAILED;
}
break;
case SETPOWERMANAGEMENT:
if ((cjIn >= sizeof (VIDEO_POWER_MANAGEMENT)) && (pvIn != NULL))
{
PVIDEO_POWER_MANAGEMENT pvpm = (PVIDEO_POWER_MANAGEMENT)pvIn;
if (pvpm->Length >= sizeof (VIDEO_POWER_MANAGEMENT))
{
switch (pvpm->PowerState)
{
case VideoPowerStandBy:
case VideoPowerOn:
SetDisplayPower(VideoPowerOn);
Result = ESC_SUCCESS;
break;
case VideoPowerOff:
case VideoPowerSuspend:
SetDisplayPower(VideoPowerOff);
Result = ESC_SUCCESS;
break;
}
}
}
if (Result != ESC_SUCCESS)
{
// Shouldn't get here if everything was ok.
SetLastError(ERROR_INVALID_PARAMETER);
Result = ESC_FAILED;
}
break;
case GETPOWERMANAGEMENT:
RETAILMSG(DBGLCD, (L"%s::GETPOWERMANAGEMENT\n", pszFname));
if ((cjOut >= sizeof (VIDEO_POWER_MANAGEMENT)) && (pvOut != NULL))
{
PVIDEO_POWER_MANAGEMENT pvpm = (PVIDEO_POWER_MANAGEMENT)pvOut;
pvpm->Length = sizeof (VIDEO_POWER_MANAGEMENT);
pvpm->DPMSVersion = 0;
pvpm->PowerState = m_VideoPowerState;
Result = ESC_SUCCESS;
}
else
{
// Shouldn't get here if everything was ok.
SetLastError(ERROR_INVALID_PARAMETER);
Result = ESC_FAILED;
}
break;
case IOCTL_POWER_CAPABILITIES:
// tell the power manager about ourselves
RETAILMSG(DBGLCD, (L"%s: IOCTL_POWER_CAPABILITIES\r\n", pszFname));
if (pvOut != NULL && cjOut == sizeof(POWER_CAPABILITIES))
{
__try
{
PPOWER_CAPABILITIES ppc = (PPOWER_CAPABILITIES) pvOut;
memset(ppc, 0, sizeof(*ppc));
ppc->DeviceDx = 0x11; // support D0 and D4
Result = ESC_SUCCESS;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
RETAILMSG(DBGLCD, (L"%s: exception in ioctl\r\n"));
}
}
break;
case IOCTL_POWER_QUERY:
if(pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE))
{
// return a good status on any valid query, since we are always ready to
// change power states.
__try
{
CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pvOut;
if(VALID_DX(NewDx))
{
// this is a valid Dx state so return a good status
Result = ESC_SUCCESS;
}
RETAILMSG(DBGLCD, (L"%s: IOCTL_POWER_QUERY %u %s\r\n", pszFname,
NewDx, Result == ESC_SUCCESS ? L"succeeded" : L"failed"));
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
RETAILMSG(DBGLCD, (L"%s: exception in ioctl\r\n"));
}
}
break;
case IOCTL_POWER_SET:
if(pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE))
{
__try
{
CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pvOut;
CEDEVICE_POWER_STATE CurrentDx;
if(VALID_DX(NewDx))
{
VIDEO_POWER_STATE ulPowerState = PmToVideoPowerState(NewDx);
SetDisplayPower(ulPowerState);
CurrentDx = VideoToPmPowerState((VIDEO_POWER_STATE)m_VideoPowerState);
Result = ESC_SUCCESS;
RETAILMSG(DBGLCD, (L"%s: IOCTL_POWER_SET %u: passing back %u\r\n", pszFname,
NewDx, CurrentDx));
}
else
{
RETAILMSG(DBGLCD,
(L"%s: IOCTL_POWER_SET: invalid state request %u\r\n", pszFname, NewDx));
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
RETAILMSG(DBGLCD, (L"%s: exception in ioctl\r\n"));
}
}
break;
case IOCTL_POWER_GET:
if(pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE))
{
__try
{
CEDEVICE_POWER_STATE CurrentDx = D0;//VideoToPmPowerState((VIDEO_POWER_STATE)m_VideoPowerState);
*(PCEDEVICE_POWER_STATE) pvOut = D0; //CurrentDx;
Result = ESC_SUCCESS;
RETAILMSG(DBGLCD, (L"%s: IOCTL_POWER_GET: passing back %u\r\n", pszFname,
CurrentDx));
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
RETAILMSG(DBGLCD, (L"%s: exception in ioctl\r\n"));
}
}
break;
}
return Result;
}
//#endif //CLEARTYPE
#undef ESC_NOT_SUPPORTED
#undef ESC_FAILED
#undef ESC_SUCCESS
void S3C24A0DISP::SetDisplayPower(ULONG PowerState)
{
static BYTE * pVideoMemory = NULL;
WORD *ptr;
// If we're already in the appropriate state, just return
if (m_VideoPowerState == PowerState)
{
return;
}
if (PowerState == VideoPowerOff)
{
m_VideoPowerState = VideoPowerOff;
m_CursorDisabled = TRUE;
CursorOff();
// Save video memory
if (NULL == pVideoMemory)
{
pVideoMemory = new BYTE [m_FrameBufferSize];
}
if (NULL != pVideoMemory)
{
memcpy(pVideoMemory, m_pPrimarySurface->Buffer(), m_FrameBufferSize);
}
// Blank the screen
memset ((void*)m_pPrimarySurface->Buffer(), 0x0, m_FrameBufferSize);
// Swap the buffer in the primary surface with that of our off screen buffer.
if (NULL != pVideoMemory)
{
BYTE * pTempBuffer = (BYTE*)m_pPrimarySurface->Buffer();
#ifdef DD_ENABLE
m_pPrimarySurface->Init(m_nScreenWidth, m_nScreenHeight, pVideoMemory, m_cbScanLineLength, m_pModeEx.modeInfo.format); //, EGPEFormatToEDDGPEPixelFormat[m_pModeEx.modeInfo.format]);
#else
m_pPrimarySurface->Init(m_nScreenWidth, m_nScreenHeight, pVideoMemory, m_cbScanLineLength, m_ModeInfo.format);
#endif // DD_ENABLE
pVideoMemory = pTempBuffer;
}
// Let the setting take effect before disabling the controller
Sleep(100);
// disable LCD controller
RETAILMSG(DBGLCD, (TEXT("SetDisplayPower: disable LCD controller \r\n")));
// Set Board Control Register (BCR) for Sharp LCD mode
//set_BCRVal (NOMASK, BCR_LCD_LQ039Q2DS01_16BPP | BCR_LCD_POWER_OFF | BCR_BACKLIGHT_OFF, INPOWERHANDLER);
//Added by APR ++
//RETAILMSG(DBGLCD, (TEXT("#####COM::PowerDown Clock before %x\n"), v_s24A0CLKPWR->rCLKCON));
//v_s24A0CLKPWR->rCLKCON &= ~(1<<22);
RETAILMSG(DBGLCD1,(TEXT("#####S3C24A0DISP::SetDisplayPower Powered Down.\n")));
//APR --
}
else
{
//Added by APR ++ Turn the clock to LCD on
//v_s24A0CLKPWR->rCLKCON |= (1<<22);
//APR --
m_VideoPowerState = VideoPowerOn;
// init "palette" area - just has some flags for 16bpp active display mode
ptr = (WORD*)m_VirtualFrameBuffer;
ptr[0] = 0x2000;
for(int index = 1; index < 16; index++)
{
ptr[index] = 0x00000000;
}
// clear rest of frame buffer out
for(index = 0; index < 320*240; index++)
{
if(index < 3200)
{
ptr[index + 16] = 0xf800;
}
else if(index < 6400)
{
ptr[index + 16] = 0x07e0;
}
else if(index < 9600)
{
ptr[index + 16] = 0x001f;
}
else
{
ptr[index + 16] = 0xffff;
}
}
// Set Board Control Register (BCR) for Sharp LCD mode
//set_BCRVal (BCR_LCD_LQ039Q2DS01_16BPP | BCR_LCD_POWER_ON | BCR_BACKLIGHT_ON, NOMASK, INPOWERHANDLER);
//
// The SA1111DB card used by the SA11X0BD platform provides a bit to
// allow us to choose between MQ200 and SA_LCD. By default we assume
// the display will be a MQ200 (so we can have a generic MQ200 driver)
// and only override it if we want to use the LCD driver. It's wrapped
// in a conditional so other SA-based systems can use this library.
//
// if (m_bClearAlternateVideoBCR != 0)
// {
// set_BCRVal (0, 0x2, INPOWERHANDLER);
// }
// Program GPIO register to enable GPIO lines 2 - 9 for use by the LCD controller
// disable LCD controller
// clear LCD Status Register
// enable LCD controller
// Restore the screen
if (NULL != pVideoMemory)
{
// Swap the buffers.
BYTE * pTempBuffer = (BYTE*)m_pPrimarySurface->Buffer();
#ifdef DD_ENABLE
m_pPrimarySurface->Init(m_nScreenWidth, m_nScreenHeight, pVideoMemory, m_cbScanLineLength, m_pModeEx.modeInfo.format); //, EGPEFormatToEDDGPEPixelFormat[m_pModeEx.modeInfo.format]);
#else
m_pPrimarySurface->Init(m_nScreenWidth, m_nScreenHeight, pVideoMemory, m_cbScanLineLength, m_ModeInfo.format);
#endif // DD_ENABLE
pVideoMemory = pTempBuffer;
// Actually copy the bits.
memcpy(m_pPrimarySurface->Buffer(), pVideoMemory, m_FrameBufferSize);
delete [] pVideoMemory;
pVideoMemory = NULL;
}
else
{
memset ((void*)m_pPrimarySurface->Buffer(), 0x0, m_FrameBufferSize);
}
m_CursorDisabled = FALSE;
//CursorOn();
m_CursorVisible = TRUE;
}
}
ULONG *APIENTRY DrvGetMasks(DHPDEV dhpdev)
{
RETAILMSG(DBGLCD, (TEXT("DrvGetMasks\r\n")));
return gBitMasks;
}
#ifndef DD_ENABLE // if not a DDraw driver, then include dummy versions of these function
void RegisterDDHALAPI(void)
{
return;
}
void HALInit()
{
RETAILMSG( 1,(TEXT("HALInit: Stub, Shouldn't have come in hereX\n")));
RETAILMSG( 1,(TEXT("HALInit: Stub, Shouldn't have come in hereX\n")));
}
#endif //DD_SUPPORT
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?