📄 display.c
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2006,2007 Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
//
// File: display.c
//
// OAL Display routines.
//
//-----------------------------------------------------------------------------
#include "bsp.h"
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
#if (BSP_DISPLAY_CONTROLLER == DISPLAY_CONTROLLER_LCDC)
//------------------------------------------------------------------------------
// External Variables
#include "splashscreen.c"
//------------------------------------------------------------------------------
// External Functions
extern VOID OALClockSetGatingMode(DDK_CLOCK_GATE_INDEX index,
DDK_CLOCK_GATE_MODE mode);
// LCDC display routines
static BOOL LCDCInitialize(int width, int height, int bpp);
static void LCDCEnable(BOOL bEnable);
#define LCD_CLOCK_SET_GATE_MODE(index, mode)\
do{\
extern PCSP_PLLCRC_REGS g_pPLLCRC;\
REG32* pPCCR = &g_pPLLCRC->PCCR0;\
if (mode)\
SETREG32(&pPCCR[CRM_PCCR_INDEX(index)], CRM_PCCR_VAL(index, 1));\
else \
CLRREG32(&pPCCR[CRM_PCCR_INDEX(index)], CRM_PCCR_VAL(index, 1));\
}while(0)
#endif
#if (BSP_DISPLAY_CONTROLLER == DISPLAY_CONTROLLER_LCDC)
//-----------------------------------------------------------------------------
//
// Function: OALDisplaySplashScreen
//
// Function intialises the display controller to display a splash screen.
//
// Parameters:
//
// Returns:
// FALSE if display is not sucessful.
//
//-----------------------------------------------------------------------------
BOOL OALDisplaySplashScreen(void)
{
int screenWidth, screenHeight, screenBpp, pixelBytes;
int bmpWidth, bmpHeight;
int w, w1;
int h;
int i, j;
BOOL success = FALSE;
BYTE *pfb;
OALMSG(OAL_FUNC, (TEXT("+OALDisplaySplashScreen\r\n")));
screenWidth = BSP_PREF_DISPLAY_WIDTH;
screenHeight = BSP_PREF_DISPLAY_HEIGHT;
screenBpp = BSP_PREF_DISPLAY_BPP;
pixelBytes = LCDC_PIXEL_SIZE_BYTES(screenBpp);
// Initialise display controller
if(!LCDCInitialize(screenWidth, screenHeight, screenBpp))
{
OALMSG(OAL_WARN, (TEXT("OALDisplaySplashScreen: DisplayInitialize failed.\r\n")));
goto displaycleanup;
}
// bitmap_height, bitmap_width contain the width, height of the splashscreen
// display. See splashscreen.c
bmpWidth = (bitmap_width > screenWidth) ? screenWidth : bitmap_width;
bmpHeight = (bitmap_height > screenHeight) ? screenHeight : bitmap_height;
w = (screenWidth - bmpWidth) / 2;
h = (screenHeight - bmpHeight) / 2;
w1 = ((screenWidth - bmpWidth) % 2 == 0)? w : w + 1;
pfb = (BYTE *)IMAGE_SHARE_FRAMEBUFFER_RAM_UA_START;
// Pre-set the screen background with white color
memset(pfb, 0xff, screenWidth * screenHeight * pixelBytes);
// Copy and centre splash screen in framebuffer.
j = bmpWidth * pixelBytes;
pfb += h * screenWidth * pixelBytes;
for(i = 0; i < bmpHeight; i++)
{
pfb += w * pixelBytes;
memcpy(pfb, &bitmap_data[i * bitmap_width], j);
pfb += j + w1 * pixelBytes;
}
// Enable display controller.
LCDCEnable(TRUE);
success = TRUE;
displaycleanup:
OALMSG(OAL_FUNC, (TEXT("-DisplaySplashScreen(%d)\r\n"), success));
return success;
}
//-----------------------------------------------------------------------------
//
// LCDC diplay control routines
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Function: LDCEnable
//
// Function enables the LCDC controller
//
// Parameters:
//
// Returns:
//
//-----------------------------------------------------------------------------
static void LCDCEnable(BOOL bEnable)
{
CSP_GPIO_REGS *pGPIO;
extern PCSP_PBC_REGS g_pPBC;
pGPIO = (CSP_GPIO_REGS *)OALPAtoUA(CSP_BASE_REG_PA_GPIO);
if(bEnable)
{
// Configure LCDC GPIO pins
OAL_IOMUX_PRI_PINS(pGPIO, GPIO_LCDC_PORT, GPIO_LCDC_MASK);
// Enable LCDC
LCD_CLOCK_SET_GATE_MODE(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_ENABLE);
LCD_CLOCK_SET_GATE_MODE(DDK_CLOCK_GATE_INDEX_HCLK_LCDC, DDK_CLOCK_GATE_MODE_ENABLE);
// Turn on lcd panel
OUTREG16(&g_pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_LCDON));
}
else
{
// Disable LCD panel
OUTREG16(&g_pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_LCDON));
// Disable LCDC
LCD_CLOCK_SET_GATE_MODE(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_DISABLE);
LCD_CLOCK_SET_GATE_MODE(DDK_CLOCK_GATE_INDEX_HCLK_LCDC, DDK_CLOCK_GATE_MODE_DISABLE);
// Reset LCDC GPIO pins
OAL_IOMUX_DISABLE_PINS(pGPIO, GPIO_LCDC_PORT, GPIO_LCDC_MASK);
}
}
//-----------------------------------------------------------------------------
//
// Function: LCDCInitialize
//
// Function intialises the LCDC controller and displays a splash screen.
//
// Parameters:
// pAddress
// [in] Ptr to CS8900 IO address base.
//
// Returns:
// FALSE if EEPROM is not detected.
//
//-----------------------------------------------------------------------------
static BOOL LCDCInitialize(int width, int height, int bpp)
{
BOOL rc = TRUE;
UINT32 pixelBytes;
UINT32 uLCDRefClk;
CSP_LCDC_REGS *pLCDC;
BSP_ARGS *pBspArgs = (BSP_ARGS *)OALPAtoUA(IMAGE_SHARE_ARGS_RAM_PA_START);
pixelBytes = LCDC_PIXEL_SIZE_BYTES(bpp);
pLCDC = (CSP_LCDC_REGS *)OALPAtoUA(CSP_BASE_REG_PA_LCDC);
// Disable LCDC clock
LCDCEnable(FALSE);
// Disable self refresh
pLCDC->RMCR &= ~CSP_BITFMASK(LCDC_RMCR_SELF_REF);
pLCDC->SSAR = IMAGE_SHARE_FRAMEBUFFER_RAM_PA_START;
pLCDC->SR = CSP_BITFVAL(LCDC_SR_YMAX, BSP_PREF_DISPLAY_HEIGHT) |
CSP_BITFVAL(LCDC_SR_XMAX, (BSP_PREF_DISPLAY_WIDTH / 16) ) |
CSP_BITFVAL(LCDC_SR_BUSSIZE, LCDC_SR_BUSSIZE_32BIT);
pLCDC->VPWR = BSP_PREF_DISPLAY_WIDTH / (4 / pixelBytes);
// disable cursor
pLCDC->CPR = CSP_BITFVAL(LCDC_CPR_OP, LCDC_CPR_OP_DISABLE) |
CSP_BITFVAL(LCDC_CPR_CC, LCDC_CPR_CC_DISABLED);
// Disable cursor blink, all settings default
pLCDC->CWHBR = CSP_BITFVAL(LCDC_CWHBR_BK_EN, LCDC_CWHBR_BK_EN_DISABLE) |
CSP_BITFVAL(LCDC_CWHBR_CW, LCDC_CWHBR_CW_CURSOR_DISABLED) |
CSP_BITFVAL(LCDC_CWHBR_CH, LCDC_CWHBR_CH_CURSOR_DISABLED) |
CSP_BITFVAL(LCDC_CWHBR_BD, LCDC_CWHBR_BD_MAX_DIV);
// CCMR: Default as on reset
pLCDC->CCMR = 0;
// Set Pixel polarity bit since color is inverted in lcd board.
uLCDRefClk = pBspArgs->clockFreq[DDK_CLOCK_SIGNAL_PERDIV3];
pLCDC->PCR =
#ifdef VGA_DISPLAY
CSP_BITFVAL(LCDC_PCR_SHARP, LCDC_PCR_SHARP_DISABLE) |
CSP_BITFVAL(LCDC_PCR_PIXPOL, LCDC_PCR_PIXPOL_ACTIVE_HIGH) |
#else
CSP_BITFVAL(LCDC_PCR_SHARP, LCDC_PCR_SHARP_ENABLE) |
CSP_BITFVAL(LCDC_PCR_PIXPOL, LCDC_PCR_PIXPOL_ACTIVE_LOW) |
#endif
CSP_BITFVAL(LCDC_PCR_SCLKSEL, LCDC_PCR_SCLKSEL_ENABLE) |
CSP_BITFVAL(LCDC_PCR_ACDSEL, LCDC_PCR_ACDSEL_USE_LPHSYNC) |
CSP_BITFVAL(LCDC_PCR_REV_VS, LCDC_PCR_REV_VS_NORMAL) |
CSP_BITFVAL(LCDC_PCR_SWAP_SEL, LCDC_PCR_SWAP_SEL_16BPP) |
CSP_BITFVAL(LCDC_PCR_END_SEL, LCDC_PCR_END_SEL_LITTLE_ENDIAN) |
CSP_BITFVAL(LCDC_PCR_SCLKIDLE, LCDC_PCR_SCLKIDLE_DISABLE) |
CSP_BITFVAL(LCDC_PCR_OEPOL, LCDC_PCR_OEPOL_ACTIVE_HIGH) |
CSP_BITFVAL(LCDC_PCR_CLKPOL, LCDC_PCR_CLKPOL_NEG_EDGE) |
CSP_BITFVAL(LCDC_PCR_LPPOL, LCDC_PCR_LPPOL_ACTIVE_HIGH) |
CSP_BITFVAL(LCDC_PCR_FLMPOL, LCDC_PCR_FLMPOL_ACTIVE_HIGH) |
CSP_BITFVAL(LCDC_PCR_PBSIZ, LCDC_PCR_PBSIZ_8BIT) |
CSP_BITFVAL(LCDC_PCR_COLOR, LCDC_PCR_COLOR_COLOR) |
CSP_BITFVAL(LCDC_PCR_TFT, LCDC_PCR_TFT_ACTIVE) |
CSP_BITFVAL(LCDC_PCR_PCD, LCDC_PCD_VALUE(uLCDRefClk, BSP_PIXEL_CLOCK_FREQ));
switch(bpp)
{
case 1:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_1BPP);
break;
case 2:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_2BPP);
break;
case 4:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_4BPP);
break;
case 8:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_8BPP);
break;
case 12:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_12BPP);
break;
case 16:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_16BPP);
break;
case 18:
pLCDC->PCR |= CSP_BITFVAL(LCDC_PCR_BPIX, LCDC_PCR_BPIX_18BPP);
break;
default:
goto cleanup;
}
pLCDC->HCR = CSP_BITFVAL(LCDC_HCR_H_WIDTH, 1) |
CSP_BITFVAL(LCDC_HCR_H_WAIT_1, 15) |
CSP_BITFVAL(LCDC_HCR_H_WAIT_2, 10);
pLCDC->VCR = CSP_BITFVAL(LCDC_VCR_V_WIDTH, 1) |
CSP_BITFVAL(LCDC_VCR_V_WAIT_1, 9) |
CSP_BITFVAL(LCDC_VCR_V_WAIT_2, 7) ;
// POR: 0 as reset default
pLCDC->POR = CSP_BITFVAL(LCDC_POR_POR, 0);
pLCDC->SCR = CSP_BITFVAL(LCDC_SCR_GRAY1, 0) |
CSP_BITFVAL(LCDC_SCR_GRAY2, 0) |
CSP_BITFVAL(LCDC_SCR_REV_TOGGLE_DELAY, 3) |
CSP_BITFVAL(LCDC_SCR_CLS_RISE_DELAY, 18) |
CSP_BITFVAL(LCDC_SCR_PS_RISE_DELAY, 0);
// Enable contrast for backlight control. Initialize to half power
pLCDC->PCCR = CSP_BITFVAL(LCDC_PCCR_PW, LCDC_PCCR_PW_MAX / 2) |
CSP_BITFVAL(LCDC_PCCR_CC_EN, LCDC_PCCR_CC_EN_ENABLE) |
CSP_BITFVAL(LCDC_PCCR_SCR, LCDC_PCCR_SCR_PIXELCLK) |
CSP_BITFVAL(LCDC_PCCR_LDMSK, LCDC_PCCR_LDMSK_DISABLE) |
CSP_BITFVAL(LCDC_PCCR_CLS_HI_WIDTH, 169);
// Settings for heavily loaded bus with SDRAM access.
// dynamic burst, High mark = 3, low mark = 1D (best setting after testing)
pLCDC->DCR = CSP_BITFVAL(LCDC_DCR_BURST, LCDC_DCR_BURST_DYNAMIC) |
CSP_BITFVAL(LCDC_DCR_HM, 0x02) |
CSP_BITFVAL(LCDC_DCR_TM, 0x10);
// Set for interrupt on output of last data to panel, end of graphic window
pLCDC->ICR = CSP_BITFVAL(LCDC_ICR_GW_INT_CON, LCDC_ICR_GW_INT_CON_END) |
CSP_BITFVAL(LCDC_ICR_INTSYN, LCDC_ICR_INTSYN_PANEL) |
CSP_BITFVAL(LCDC_ICR_INTCON, LCDC_ICR_INTCON_BOF);
// Disable All interrupts
pLCDC->IER = 0;
// Setup graphic window DMA
// Don't change unless primary buffer DMA settings are changed
pLCDC->GWDCR = CSP_BITFVAL(LCDC_GWDCR_GWBT, LCDC_GWDCR_GWBT_DYNAMIC) |
CSP_BITFVAL(LCDC_GWDCR_GWHM, 0x02) |
CSP_BITFVAL(LCDC_GWDCR_GWTM, 0x10);
// Disable graphic window.
pLCDC->GWCR = CSP_BITFVAL(LCDC_GWCR_GWE, 0);
// We're done
rc = TRUE;
cleanup:
OALMSG(!rc, (TEXT("LCDCInitialize: rc (%d)\r\n"), rc));
return rc;
}
#else
//-----------------------------------------------------------------------------
//
// Function: OALDisplaySplashScreen
//
// Function intialises the display controller to display a splash screen.
//
// Parameters:
//
// Returns:
// FALSE if display is not sucessful.
//
//-----------------------------------------------------------------------------
BOOL OALDisplaySplashScreen(void)
{
return TRUE;
}
#endif // BSP_DISPLAY_CONTROLLER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -