⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdgpe.cpp

📁 AU1100嵌入式处理器lcd显示驱动程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			rgbIdentity[i].peRed = (BYTE)i;
			rgbIdentity[i].peGreen = (BYTE)i;
			rgbIdentity[i].peBlue = (BYTE)i;
		}
	}

	SetPalette(rgbIdentity, 0, 256);
/***********/

	// clear out all of display memory
	memset(m_pLAW, 0x0, m_FbSize);

	// force allocations to align to 32 bits
#ifdef DDRAW_ENABLE
   m_pVideoMemory = new SurfaceHeap(m_FbSize, (ADDRESS)m_pLAW, NULL, NULL);

   DEBUGMSG (1, (TEXT("Au1100LCD::m_FbSize=%x(%u)\r\n"), m_FbSize, m_FbSize));
   DEBUGMSG (1, (TEXT("Au1100LCD::Allocated VRAM size=%x(%u)\r\n"),
	   m_pVideoMemory->Available(), m_pVideoMemory->Available()));
#else
	m_p2DVideoMemory = new Node2D(m_pMode->width,
	  m_FbSize / m_LineSizeInBytes /*m_FbSize / m_pMode->width*/,
	  0, 0, 32 / m_pMode->Bpp);
#endif

	if (FAILED(sc = AllocSurface(&m_pPrimarySurface, m_pMode->width, m_pMode->height, m_pMode->format, GPE_REQUIRE_VIDEO_MEMORY)))
	{
		RETAILMSG (1, (TEXT("Couldn't allocate primary surface\r\n")));
		return sc;
	}
	else RETAILMSG(1, (TEXT("allocSurface() ok!\r\n")));

	if ((m_cursor = new SOFT_CURSOR(gpGPE)) == NULL)
	{
		RETAILMSG(1,(TEXT("ERROR: SWCURSOR() FAIL\r\n")));
	}
	sc = m_cursor->CreateSurfaces();
	RETAILMSG(1,(TEXT("cursor surfaces: %d\r\n"), sc));

	DEBUGMSG(1, (TEXT("Leaving Au1100LCD::SetMode\r\n")));
	return S_OK;
}

/********************************************************************/
SCODE
Au1100LCD::SetPalette(
	const PALETTEENTRY *src,
	unsigned short firstEntry,
	unsigned short numEntries )
{
   DEBUGMSG (1, (TEXT("Au1100::SetPalette\r\n")));
   if( firstEntry < 0 || firstEntry + numEntries > 256 )
      return E_INVALIDARG;

   //In case there's any application call SetPalette() at display time,
   //we may have to add the next line to set palette only during 
   //Vertical None-Display period to avoid "snowy" effect.
   //   WaitForVBlank();
#if 0 /* FIX!!! */
   for( ; numEntries; numEntries-- )
   {
      m_Reg[Reg::LutAddr] = (unsigned char)(firstEntry++);
      m_Reg[Reg::LutData] = src->peRed;
      m_Reg[Reg::LutData] = src->peGreen;
      m_Reg[Reg::LutData] = src->peBlue;
      src++;
   }
#endif
   return S_OK;
}

/********************************************************************/
// Return TRUE if in Vertical Blank, otherwise FALSE
int
Au1100LCD::InVBlank()
{
//	DEBUGMSG(1, (L"lcd_intstatus=%x\r\n", m_Reg->intstatus));

	if (m_Reg->intstatus & LCD_INT_SA)
	{
		m_Reg->intstatus |= LCD_INT_SA; // clear Frame Done bit
		return TRUE;
	}
	else
		return FALSE;
}

SCODE	Au1100LCD::WrappedEmulatedLine (GPELineParms *lineParameters)
{
	SCODE	retval;
	RECTL	bounds;
	int		N_plus_1;				// Minor length of bounding rect + 1

	// calculate the bounding-rect to determine overlap with cursor
	if (lineParameters->dN)			// The line has a diagonal component (we'll refresh the bounding rect)
	{
		N_plus_1 = 2 + ((lineParameters->cPels * lineParameters->dN) / lineParameters->dM);
	}
	else
	{
		N_plus_1 = 1;
	}

	switch(lineParameters->iDir)
	{
		case 0:
			bounds.left = lineParameters->xStart;
			bounds.top = lineParameters->yStart;
			bounds.right = lineParameters->xStart + lineParameters->cPels + 1;
			bounds.bottom = bounds.top + N_plus_1;
			break;
		case 1:
			bounds.left = lineParameters->xStart;
			bounds.top = lineParameters->yStart;
			bounds.bottom = lineParameters->yStart + lineParameters->cPels + 1;
			bounds.right = bounds.left + N_plus_1;
			break;
		case 2:
			bounds.right = lineParameters->xStart + 1;
			bounds.top = lineParameters->yStart;
			bounds.bottom = lineParameters->yStart + lineParameters->cPels + 1;
			bounds.left = bounds.right - N_plus_1;
			break;
		case 3:
			bounds.right = lineParameters->xStart + 1;
			bounds.top = lineParameters->yStart;
			bounds.left = lineParameters->xStart - lineParameters->cPels;
			bounds.bottom = bounds.top + N_plus_1;
			break;
		case 4:
			bounds.right = lineParameters->xStart + 1;
			bounds.bottom = lineParameters->yStart + 1;
			bounds.left = lineParameters->xStart - lineParameters->cPels;
			bounds.top = bounds.bottom - N_plus_1;
			break;
		case 5:
			bounds.right = lineParameters->xStart + 1;
			bounds.bottom = lineParameters->yStart + 1;
			bounds.top = lineParameters->yStart - lineParameters->cPels;
			bounds.left = bounds.right - N_plus_1;
			break;
		case 6:
			bounds.left = lineParameters->xStart;
			bounds.bottom = lineParameters->yStart + 1;
			bounds.top = lineParameters->yStart - lineParameters->cPels;
			bounds.right = bounds.left + N_plus_1;
			break;
		case 7:
			bounds.left = lineParameters->xStart;
			bounds.bottom = lineParameters->yStart + 1;
			bounds.right = lineParameters->xStart + lineParameters->cPels + 1;
			bounds.top = bounds.bottom - N_plus_1;
			break;
		default:
			DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Invalid direction: %d\r\n"), lineParameters->iDir));
			return E_INVALIDARG;
	}

	// check for line overlap with cursor and turn off cursor if overlaps
    if (m_cursor->CursorIntersect(&bounds)) {
        m_cursor->HideSWCursor();
        m_bCursorForcedOff = TRUE;
    }

	// do emulated line
	retval = EmulatedLine(lineParameters);

	// se if cursor was forced off because of overlap with line bouneds and turn back on
    if (m_bCursorForcedOff) {
        m_cursor->ShowSWCursor();
        m_bCursorForcedOff = FALSE;
    }

	return	retval;
}



/********************************************************************/
SCODE
Au1100LCD::Line(GPELineParms *pLineParms, EGPEPhase phase)
{
	if (phase == gpeSingle || phase == gpePrepare)
	{
		//DispPerfStart (ROP_LINE);

        if (pLineParms->pDst == PrimarySurface()) {
            pLineParms->pLine = (SCODE (GPE::*)(struct GPELineParms *)) WrappedEmulatedLine;
        } else {
		    pLineParms->pLine = EmulatedLine;
        }
	}
	else if (phase == gpeComplete)
	{
		//DispPerfEnd (0);
	}

	return S_OK;
}

#ifndef DDRAW_ENABLE
void	RegisterDDHALAPI(void)
{
	return;	// no DDHAL support
}
#endif

ULONG	*APIENTRY	DrvGetMasks(DHPDEV dhpdev)
{
	int Bpp = ((Au1100LCD *)gpGPE)->GetBpp();

	if (Bpp == 16)
		return RGB565; //BitMasks16;
	else
		return RGB565; //BitMasks;
}

BOOL APIENTRY GPEEnableDriver(          // This gets around problems exporting from .lib
   ULONG          iEngineVersion,
   ULONG          cj,
   DRVENABLEDATA *pded,
   PENGCALLBACKS  pEngCallbacks);

BOOL APIENTRY DrvEnableDriver(
   ULONG          iEngineVersion,
   ULONG          cj,
   DRVENABLEDATA *pded,
   PENGCALLBACKS  pEngCallbacks)
{
	return GPEEnableDriver( iEngineVersion, cj, pded, pEngCallbacks );
}

#ifdef SHOW_FRAMERATE

void Au1100LCD::DisplayFrameRate( void )
{
    DWORD time2;

	if (!m_bShowFrameRate)
	{
		return;
	}

    m_dwFrameCount++;
    time2 = GetTickCount() - m_dwFrameTime;
    if( time2 > 1000 )
    {
        m_dwFrames = (m_dwFrameCount*1000)/time2;
        m_dwFrameTime = GetTickCount();
        m_dwFrameCount = 0;
    }
    if( m_dwFrames == 0 )
    {
        return;
    }

    if (m_dwFrames != m_dwFramesLast)
    {
        m_dwFramesLast = m_dwFrames;
    }
	
	RETAILMSG(1,(TEXT("Frame rate: %u fps\r\n"), m_dwFrames));

}

#endif SHOW_FRAMERATE

VOID Au1100LCD::PowerHandler( BOOL bOff )
{
   if (bOff)    
   { 
		// backlight driver
		// will turn the backlight off.
	   	m_Reg->intstatus &= ~LCD_INT_SD;
	   	m_Reg->intenable |= LCD_INT_SD;
		m_Reg->control &= ~LCD_CONTROL_GO;
		while( !(m_Reg->intstatus & LCD_INT_SD) ) {
			;
		}

#ifdef PLATFORM_AU1100LCD_POWERDOWN_CODE
		PLATFORM_AU1100LCD_POWERDOWN_CODE
#endif

   }
   else
   {  //power on
		uint32 sys_clksrc;
		sys_clksrc = (m_Sys->clksrc & ~0x000003e0); /* zero-out out LCD bits */
		sys_clksrc |= m_mode->mode_toyclksrc;
		m_Sys->clksrc = sys_clksrc;

#ifdef PLATFORM_AU1100LCD_POWERUP_CODE
		PLATFORM_AU1100LCD_POWERUP_CODE
#endif

		SetRegisters();

	    m_cursor->ShowSWCursor();
   }
}

VOID Au1100LCD::SetRegisters(VOID)
{
   	/*
	 * Setup LCD controller
	 */
	/* FIX!!! Need to accomodate for swivel mode and 12bpp, <8bpp*/
	switch (m_mode->mode_control & LCD_CONTROL_SM)
	{
	case LCD_CONTROL_SM_0:
	case LCD_CONTROL_SM_180:
		m_words = ((m_ModeInfo.width * m_ModeInfo.height * m_ModeInfo.Bpp) / 32);
		break;
	case LCD_CONTROL_SM_90:
	case LCD_CONTROL_SM_270:
		m_words = ((m_ModeInfo.width * m_ModeInfo.Bpp) / 32);
		break;
	}
#ifdef FB_CACHED
	m_Reg->control = m_mode->mode_control | LCD_CONTROL_C;
#else
	m_Reg->control = m_mode->mode_control & ~LCD_CONTROL_C;
#endif
	m_Reg->intstatus &= ~(LCD_INT_SA|LCD_INT_SS|LCD_INT_S1|LCD_INT_S0); // LCD_INT_SSL bit is read only, default to 0
	m_Reg->intenable &= ~(LCD_INT_SA|LCD_INT_SS|LCD_INT_S1|LCD_INT_S0);
	m_Reg->horztiming = m_mode->mode_horztiming;
	m_Reg->verttiming = m_mode->mode_verttiming;
	m_Reg->clkcontrol = m_mode->mode_clkcontrol;

	if (isDSTN(m_mode->mode_control))
	{
		m_Reg->words = (m_words / 2) - 1;
		m_Reg->dmaaddr0 = m_pFb + ((m_words * 4) / 2);
		m_Reg->dmaaddr1 = m_pFb;
	}
	else
	{
		m_Reg->words = m_words - 1;
		m_Reg->dmaaddr0 = m_pFb;
	}

#ifdef PLATFORM_AU1100LCD_POWERUP_CODE
	PLATFORM_AU1100LCD_POWERUP_CODE
#endif

	m_Reg->control |= LCD_CONTROL_GO;
}

ULONG
Au1100LCD::DrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn,
                    ULONG cjOut, PVOID pvOut)
{
		// screen rotation escape codes supported just enough to inform
		// the system of our current angle so the touch driver operates correctly
	if (iEsc == DRVESC_GETSCREENROTATION)
	{
		*(int *)pvOut = ((BYTE)m_iRotate);
		return DISP_CHANGE_SUCCESSFUL; 
	}
    
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -