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

📄 lcd_optr.c

📁 Cirrus Logic EP7312处理器部分控制程序。
💻 C
字号:
//****************************************************************************
//
// LCD_OPTREX.C - Routines to enable and draw on the Optrex DMF-50944NCU-Fw-2 
// color LCD panel, at a resolution of 320x3[R.G.B](W) x 240(H).
//
// Copyright (c) 2001 Cirrus Logic, Inc.
//
//****************************************************************************
#include "ep7312.h"
#include "lib7312.h"

//****************************************************************************
//
// LCDColorEnable initializes the control logic for the LCD panel.
//
//****************************************************************************
void LCDColorEnable(void)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
    unsigned long ulLcdConfig, ulLineLength, ulVideoBufferSize;
    
    //
    // Determine the value to be programmed into the LCD controller in the
    // EP7312 to properly drive the Color LCD panel at 320x3x240, 4 bits per
    // pixel, at 80Hz.
    //
    ulVideoBufferSize = (((320 * 3) * 240 * 4) / 128) - 1;
    ulLineLength = ((320 * 3) / 16) - 1;
    ulLcdConfig = HwLcdControlGreyEnable |
                  HwLcdControlGrey4Or2 |
                  (0x13 << HwLcdControlAcPrescaleShift) |
                  (1 << HwLcdControlPixelPrescaleShift) |
                  (ulLineLength << HwLcdControlLineLengthShift) |
                  (ulVideoBufferSize << HwLcdControlBufferSizeShift);

    //
    // Configure the palette to be a one-to-one mapping of the pixel values to
    // the available LCD pixel intensities.
    //
    pulPtr[HwPaletteLSW >> 2] = 0x76543210;
    pulPtr[HwPaletteMSW >> 2] = 0xFEDCBA98;

    //
    // Program the LCD controller with the previously determined configuration.
    //
    pulPtr[HwLcdControl >> 2] = ulLcdConfig;

    //
    // Set the LCD frame buffer start address.
    //
    pulPtr[HwLcdFrameBuffer >> 2] = HwLcdBaseAddress >> 28;
}

//****************************************************************************
//
// LCDColorOn turns on the LCD panel.
//
//****************************************************************************
void LCDColorOn(void)
{																	 
	unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
	int loop;

	pulPtr[HwControl >> 2] |= HwControlLcdEnable;
	((unsigned char *)pulPtr)[HwDdrD] = 0;
	((unsigned char *)pulPtr)[HwPortD] |= HwPortDLCDPower;

	//delay
	for(loop = 0; loop < 500; loop++)
	{
	}

	((unsigned char *)pulPtr)[HwPortD] |= HwPortDLCDDcDcPower;

}

//****************************************************************************
//
// LCDColorOff turns off the LCD panel.
//
//****************************************************************************
void LCDColorOff(void)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;
    int iDelay;

    //
    // Power off the LCD DC-DC converter.
    //
    ((unsigned char *)pulPtr)[HwPortD] &= ~HwPortDLCDDcDcPower;

    //
    // Delay for a little while.
    //
    for(iDelay = 0; iDelay < 500; iDelay++)
    {
    }

    //
    // Power off the LCD panel.
    //
    ((unsigned char *)pulPtr)[HwPortD] &= ~HwPortDLCDPower;

    //
    // Power off the LCD controller.
    //
    pulPtr[HwControl >> 2] &= ~HwControlLcdEnable;
}

//****************************************************************************
//
// LCDColorBacklightOn turns on the backlighting on the LCD panel.
//
//****************************************************************************
void LCDColorBacklightOn(void)
{
	unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;

	((unsigned char *)pulPtr)[HwPortD] |= HwPortDLCDBacklightPower;
}

//****************************************************************************
//
// LCDColorBacklightOff turns off the backlighting on the LCD panel.
//
//****************************************************************************
void LCDColorBacklightOff(void)
{
	unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;

	((unsigned char *)pulPtr)[HwPortD] &= ~HwPortDLCDBacklightPower;
}

//****************************************************************************
//
// LCDColorContrastEnable enables the constrast setting on the LCD panel.
//
//****************************************************************************
void LCDColorContrastEnable(void)
{
	unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;

	pulPtr[HwPumpControl >> 2] |= 0x00000800; 
}

//****************************************************************************
//
// LCDColorContrastDisable disables the constrast setting on the LCD panel.
//
//****************************************************************************
void LCDColorContrastDisable(void)
{
	unsigned long * volatile pulPtr = (unsigned long *)HwBaseAddress;

	pulPtr[HwPumpControl >> 2] &= ~0x00000800; 
}

//****************************************************************************
//
// LCDColorCls clears the LCD frame buffer.
//
//****************************************************************************
void LCDColorCls(void)
{
    char *pcPtr = (char *)HwLcdBaseAddress;
    int iIdx;

    //
    // Fill the frame buffer with zeros.  LCD is 320x3x240.
    //
    for(iIdx = 0; iIdx < ((LCD_X_SIZE * 3) * LCD_Y_SIZE) / 2; iIdx++)
    {
        *pcPtr++ = 0x00;
    }
}

//****************************************************************************
//
// LCDColorSetPixel sets the color of the specified color.
//
//****************************************************************************
void LCDColorSetPixel(long lX, long lY, CPixel color)
{
   unsigned char * volatile pucPtr;
   unsigned long ulPixel ;

   //
   // Make sure the specified pixel is valid.
   //
   if((lX < 0) || (lX >= LCD_X_SIZE) || (lY < 0) || (lY >= LCD_Y_SIZE))
   {   
      return;
   }

   //
   // Determine the pixel number.
   // 
   ulPixel = lX + (lY * LCD_X_SIZE);

   //
   // Compute the address of the pixel.
   //
   pucPtr = (unsigned char *)(HwLcdBaseAddress + ((ulPixel * 3) / 2));

   //
   // Determine where the pixel starts - first nibble if there's no remainder,
   // second nibble if there is a remainder.  Then set the pixel color.
   //
   if((ulPixel * 3) % 2)
   {
       *pucPtr = (*pucPtr & 0x0F) | (color.r << 4);
       pucPtr++;
       *pucPtr = (*pucPtr & 0xF0) | color.g;
       *pucPtr = (*pucPtr & 0x0F) | (color.b << 4);
   }
   else
   {
       *pucPtr = (*pucPtr & 0xF0) | color.r;
       *pucPtr = (*pucPtr & 0x0F) | (color.g << 4);
       pucPtr++;
       *pucPtr = (*pucPtr & 0xF0) | color.b;
   }
}

⌨️ 快捷键说明

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