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

📄 xslcdcontroller.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document.
**  Except as permitted by such license, no part of this document may be
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation.
**
**  FILENAME:       lcdcontroller.c
**
**  PURPOSE:        API functions for the LCD Controller
**
**  LAST MODIFIED:  $Modtime: 7/24/03 11:47a $
******************************************************************************/

/************* Header Files *************/

#include <string.h>
#include <stdio.h>
#include "systypes.h"
#include "dm_errors.h"
#define LCD_GLOBALS
#include "xslcdcontroller.h"
#include "xsClkMgr.h"
#include "cotulla.h"
#include "mallocx.h"
#include "xsost.h"
#include "xspwm.h"
#include "BoardControl.h"
#include "font.h"
#include "ROS.h"
#include "FIFO.h"
#include "XsLcdParams.h"
#include "timedelays.h"

/************* Global Variables *************/

UINT16 XsLcdBg = 0x0014;
UINT16 XsLcdFg = 0xffff;
UINT8 XsLcdFontScale;
int XsLcdTask;
FrameT *frameP = NULL;

/************* Local Variables *************/

#define BTLR 0  // Scan is Bottom to Top, Left to Right
#define LRTB 1  // Scan is Left to Right, Top to Bottom
#define TBRL 2  // Scan is Top to Bottom, Right to Left
#define LRBT 3  // Scan is Left to Right, Bottom to Top
UINT XsLcdOrient;

static DM_LcdDefinition_T *lcdPanelP;

static INT16 x, y; // Text cursor, (0, 0) is upper left.

static UINT32 bmpHeader[] = {
	0x10364d42, 0x0000000E, 0x00360000, 0x00280000,
	0x01E00000, 0x02800000, 0x00010000, 0x00000018,
	0x10000000, 0x0000000E, 0x00000000, 0x00000000,
	0x00000000
} ;

static FIFO_T *fifo;

/************* Local Functions *************/

/*
*******************************************************************************
*
* FUNCTION:         calculateBpp
*
* DESCRIPTION:      Calculates the required Bpp value for a color depth.
*
* INPUT PARAMETERS: UINT colorDepth - The color depth.
*
* RETURNS:          UINT - The calculated Bpp.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        XsLcdHWSetup
*
* PROTOTYPE:        static UINT calculateBpp(UINT colorDepth);
*
*******************************************************************************
*/

static UINT calculateBpp(UINT colorDepth)
{
    UINT bppVal = 0;
    UINT colorDepthTrial = 1;


    PostDisplayProgress(ERR_L_LCD, 0, 0);
    //For this LCD controller, the BPP field in the register is set so that colorDepth = 2^BPP
    while (colorDepthTrial < colorDepth)
    {
        bppVal++;
        colorDepthTrial <<= 1;
    }

    return bppVal;

}

/*
*******************************************************************************
*
* FUNCTION:         allocateFrame
*
* DESCRIPTION:      Computes and allocates memory for a frame buffer.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          ErrorT - Status.
*
* GLOBAL EFFECTS:   frameP set to the frame address..
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        XsLcdHWSetup
*
* PROTOTYPE:        static ErrorT allocateFrame(void);
*
*******************************************************************************
*/

static ErrorT allocateFrame(void)
{
    UINT32 size;

    PostDisplayProgress(ERR_L_LCD, 1, 0);
    // Acquire a frame buffer address from the memory manager.
    // But first compute the frame buffer size.
    size = (lcdPanelP->extraLines + lcdPanelP->panelWidth) *
      lcdPanelP->panelHeight * (lcdPanelP->colorDepth/8);

    frameP = (FrameT *)malloc(size + sizeof(FrameHeaderT));

    if (frameP == NULL)
        return ERRORCODEX(ERR_L_LCD, 1, 0, ERR_T_NO_MEM_AVAIL);

    PostDisplayProgress(ERR_L_LCD, 1, 1);
    // Fill in the Frame Header.
    frameP->header.size = size;
    frameP->header.horizPixel = lcdPanelP->panelWidth;
    frameP->header.vertPixel = lcdPanelP->panelHeight;
    frameP->header.extraLines = lcdPanelP->extraLines;
    
    return ERR_NONE;
}

/*
*******************************************************************************
*
* FUNCTION:         setupDma
*
* DESCRIPTION:      This function sets up DMA for the LCD.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          None.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        XsLcdHWSetup.
*
* PROTOTYPE:        static ErrorT setupDma(void);
*
*******************************************************************************
*/

#define ARB_CNTRL (*(PUINT32)0x48000048)
static ErrorT setupDma(void)
{
    PostDisplayProgress(ERR_L_LCD, 2, 0);
    // Fill in the DMA descriptor.
    if (VirtualToPhysical(&frameP->header.DmaDescriptor, &frameP->header.DmaDescriptor.FDADR))
        return ERRORCODEX(ERR_L_LCD, 2, 0, ERR_T_ILLPARM_VTOP);
    PostDisplayProgress(ERR_L_LCD, 2, 1);
    if (VirtualToPhysical(frameP->buffer, &frameP->header.DmaDescriptor.FSADR))
        return ERRORCODEX(ERR_L_LCD, 2, 1, ERR_T_ILLPARM_VTOP);
    PostDisplayProgress(ERR_L_LCD, 2, 2);
    frameP->header.DmaDescriptor.FIDR =  0x0; // just clear the frame ID register
    frameP->header.DmaDescriptor.LDCMD = frameP->header.size;
    
    ARB_CNTRL = 0x10000211;
    
    return ERR_NONE;
}

/*
*******************************************************************************
*
* FUNCTION:         first
*
* DESCRIPTION:      This function "wakes" the LCD task.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          None.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        First character put to the LCD FIFO.
*
* PROTOTYPE:        static void first(void);
*
*******************************************************************************
*/

static void first(void)
{
    if (frameP == NULL) return;
    if (XsLcdTask) ROS_Timer(XsLcdTask, 2, 2);
    else XsLcdOut();  // If the task doesn't exist just go do it.
}

/*
*******************************************************************************
*
* FUNCTION:         last
*
* DESCRIPTION:      This function "sleeps" the LCD task.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          None.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        Last character removed from the LCD FIFO.
*
* PROTOTYPE:        static void last(void);
*
*******************************************************************************
*/

static void last(void) {
    if (XsLcdTask) ROS_Timer(XsLcdTask, 0, 0);
}

/************* Global Functions *************/

/*
*******************************************************************************
*
* FUNCTION:         XsLcdScroll
*
* DESCRIPTION:      This function scrolls the LCD one text line.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          None.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        XsLcdChar()
*
* PROTOTYPE:        void XsLcdScroll(void);
*
*******************************************************************************
*/

void XsLcdScroll(void)
{
    INT z, w;
    PUINT16 p;
   
    if (XsLcdOrient == BTLR) {  // Scan is Bottom to Top, Left to Right
//        PostDisplayProgress(ERR_L_LCD, 0xf, 0);
        memmove(                    // Scroll
            frameP->buffer+FONT_VERT_PIX*XsLcdFontScale,
            frameP->buffer,
            frameP->header.size-FONT_VERT_PIX*XsLcdFontScale*2
        );
//        PostDisplayProgress(ERR_L_LCD, 0xf, 1);
        p = frameP->buffer;         // Clear last line.
        for (
            z=0;
            z<frameP->header.vertPixel;
            z++, p+=frameP->header.horizPixel-FONT_VERT_PIX*XsLcdFontScale
        ) for (w=0; w<FONT_VERT_PIX*XsLcdFontScale; w++) *(p++) = XsLcdBg;
//        PostDisplayProgress(ERR_L_LCD, 0xf, 2);
    } else if (XsLcdOrient == LRTB) {   // Scan is Left to Right, Top to Bottom
        w = frameP->header.horizPixel*XsLcdFontScale*FONT_VERT_PIX; // Size of one line in pixels.
//        PostDisplayProgress(ERR_L_LCD, 0xf, 3);
        memcpy(                     // Scroll
            frameP->buffer,
            frameP->buffer+w,
            frameP->header.size-w*2
        );
//        PostDisplayProgress(ERR_L_LCD, 0xf, 4);
        p = frameP->buffer+frameP->header.size/2-w; // Clear last line.
        for (z=0; z<w; z++)
            *(p++) = XsLcdBg;
//        PostDisplayProgress(ERR_L_LCD, 0xf, 5);
    } else if (XsLcdOrient == TBRL) {
//        PostDisplayProgress(ERR_L_LCD, 0xf, 6);
        memcpy(                    // Scroll
            frameP->buffer,
            frameP->buffer+FONT_VERT_PIX*XsLcdFontScale,
            frameP->header.size-FONT_VERT_PIX*XsLcdFontScale*2
        );
//        PostDisplayProgress(ERR_L_LCD, 0xf, 7);
        p = frameP->buffer+frameP->header.horizPixel-FONT_VERT_PIX*XsLcdFontScale; // Clear last line.
        for (
            z=0;
            z<frameP->header.vertPixel;
            z++, p+=frameP->header.horizPixel-FONT_VERT_PIX*XsLcdFontScale
        ) for (w=0; w<FONT_VERT_PIX*XsLcdFontScale; w++) *(p++) = XsLcdBg;
//        PostDisplayProgress(ERR_L_LCD, 0xf, 8);
    }
}

/*
*******************************************************************************
*
* FUNCTION:         XsLcdOn
*
* DESCRIPTION:      This function turns the LCD on.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          None.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            None.
*
* CALLED BY:        Anyone.
*
* PROTOTYPE:        void XsLcdOn(void);
*
*******************************************************************************
*/

void XsLcdOn(void)
{
    PostDisplayProgress(ERR_L_LCD, 4, 0);
    LCDCTRL_REG_BASE->LCCR0 |= LCD_LCCR0_ENB_LCDEN;
    PostDisplayProgress(ERR_L_LCD, 4, 1);
/*
printf("LCCR0 = %08x\r\n", LCDCTRL_REG_BASE->LCCR0);
printf("LCCR1 = %08x\r\n", LCDCTRL_REG_BASE->LCCR1);
printf("LCCR2 = %08x\r\n", LCDCTRL_REG_BASE->LCCR2);
printf("LCCR3 = %08x\r\n", LCDCTRL_REG_BASE->LCCR3);
*/
}

/*
*******************************************************************************
*
* FUNCTION:         XsLcdHWSetup
*
* DESCRIPTION:      This function is the hardware setup for this driver.
*
* INPUT PARAMETERS: None.
*
* RETURNS:          ErrorT - Status.
*
* GLOBAL EFFECTS:   None.
*
* ASSUMPTIONS:      None.
*
* CALLS:            setupDma(), allocateFrame(), calculateBpp()
*
* CALLED BY:        Anyone.
*
* PROTOTYPE:        ErrorT XsLcdHWSetup(void);
*
*******************************************************************************
*/

ErrorT XsLcdHWSetup(void)
{
    int lines = 0;
    ErrorT retVal;
/*
printf("SCR = %08X\r\n", GetSCR());
printf("LCD ID = %08X\r\n", GetLcdPanelID());
printf("LCD Orientation = %08X\r\n", GetLcdPanelOrientation());
*/
    switch (GetLcdPanelID()) {
    case LCDID_SHARP_QVGA:
        lcdPanelP = &Sharp_LQ057Q3DC02;
        XsLcdFontScale = 1;
//        XsLcdOrient = GetLcdPanelOrientation() ? TBRL : LRTB;
        XsLcdOrient = GetLcdPanelOrientation() ? TBRL : LRBT;
        break;
    case LCDID_SAMSUNG_QVGA:
        lcdPanelP = &Samsung_LTV350QV_F05;
        XsLcdFontScale = 1;
        XsLcdOrient = GetLcdPanelOrientation() ? LRTB : BTLR;
        break;
    case LCDID_TOSHIBA_VGA_16:
        lcdPanelP = &Toshiba_LTM04C380K;
        XsLcdFontScale = 1;//2;	hzh
        XsLcdOrient = GetLcdPanelOrientation() ? LRTB : BTLR;
        break;
	//===hzh
	case LCDID_CRT_VGA_16:
		lcdPanelP = &CRT_640X480;
        XsLcdFontScale = 1;
        XsLcdOrient = GetLcdPanelOrientation() ? LRTB : BTLR;
		break;
    default:
        return ERRORCODEX(ERR_L_LCD, 5, 0, ERR_T_BADLCDDETECT);
        break;
    }
    
    PostDisplayProgress(ERR_L_LCD, 5, 0);
	//Enable the LCD clock and the PWM clock
	xsCMEnableClock(CK_PWM0);
    PostDisplayProgress(ERR_L_LCD, 5, 1);
	xsCMEnableClock(CK_LCD);

    PostDisplayProgress(ERR_L_LCD, 5, 2);
    //Allocate the frame buffer
    retVal = allocateFrame();
    if (retVal != ERR_NONE) return retVal;
    PostDisplayProgress(ERR_L_LCD, 5, 3);
    XsLcdClear();
    
    PostDisplayProgress(ERR_L_LCD, 5, 5);
    //Setup the DMA
    retVal = setupDma();
    if (retVal != ERR_NONE) return retVal;

    PostDisplayProgress(ERR_L_LCD, 5, 4);
    // Setup Control Register 0
    LCDCTRL_REG_BASE->LCCR0 = LCD_LCCR0_RDSTM | LCD_LCCR0_CMDIM |
      LCD_LCCR0_LDM_NOINT | LCD_LCCR0_SFM_SOFNOINT |
      LCD_LCCR0_IUM_FIFONOINT | LCD_LCCR0_EFM_EOFNOINT | LCD_LCCR0_PAS_ACTDISP |
      LCD_LCCR0_QDM_NOINT | LCD_LCCR0_BM_BSNOINT | LCD_LCCR0_OUM_FIFONOINT;

    PostDisplayProgress(ERR_L_LCD, 5, 6);
    // Setup control register 1
    LCDCTRL_REG_BASE->LCCR1 = (lcdPanelP->panelWidth-1) << LCD_LCCR1_PPL_SHIFT |
      lcdPanelP->horizSyncPW << LCD_LCCR1_HSW_SHIFT |
      lcdPanelP->horizELW << LCD_LCCR1_ELW_SHIFT |
      lcdPanelP->horizBLW << LCD_LCCR1_BLW_SHIFT;

    // If dual panel we split the lines for vertical lines per panel as
    // both run in parallel.
    if (lcdPanelP->dualPanel)
    {
      lines = lcdPanelP->panelHeight/2 + lcdPanelP->extraLines;
    }
    else
    {
      lines = lcdPanelP->panelHeight + lcdPanelP->extraLines;
    }

    PostDisplayProgress(ERR_L_LCD, 5, 7);
    // Setup control register 2
    LCDCTRL_REG_BASE->LCCR2 = (lines-1) << LCD_LCCR2_LPP_SHIFT |
      lcdPanelP->vertSyncPW << LCD_LCCR2_VSW_SHIFT |
      lcdPanelP->vertEFW << LCD_LCCR2_EFW_SHIFT |
      lcdPanelP->vertBFW << LCD_LCCR2_BFW_SHIFT;

⌨️ 快捷键说明

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