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

📄 lpc177x_8x_lcd.c

📁 NXPl788上lwip的无操作系统移植,基于Embest开发板
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
* $Id$		lpc177x_8x_lcd.c			2011-10-14
*//**
* @file		lpc177x_8x_lcd.c
* @brief	Contains all functions support for LCD firmware library
*			on LPC177x_8x
* @version	1.0
* @date		14. October. 2011
* @author	NXP MCU SW Application Team
* 
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors'
* relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers.  This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
**********************************************************************/
#ifdef __BUILD_WITH_EXAMPLE__
#include "lpc177x_8x_libcfg.h"
#else
#include "lpc177x_8x_libcfg_default.h"
#endif /* __BUILD_WITH_EXAMPLE__ */
#ifdef _LCD

#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_pinsel.h"
#include "lpc177x_8x_gpio.h"
#include "lpc177x_8x_lcd.h"

uint32_t lcd_hsize = 0, lcd_vsize = 0;
uint32_t lcd_cursor_base_addr = 0;
uint32_t lcd_cursor_size = 64;
LCD_Config_Type  lcd_config;
static uint8_t bits_per_pixel[] = {  1, 2, 4, 8, 16, 32, 16, 16  };
uint32_t rect[1024];


static void LCD_SetHorizontalTiming(LCD_HConfig_Type* pConfig);
static void LCD_SetVertialTiming(LCD_VConfig_Type* pConfig);
static void LCD_SetPolarity(LCD_TYPES lcd_type, LCD_POLARITY_Type* pConfig);
static void LCD_CtrlSetup(LCD_Config_Type* pConfig);

/** @addtogroup LCD_Private_Functions LCD Private Function
 * @ingroup LCD
 * @{
 */


/*********************************************************************//**
 * @brief		Init LCD. The input clock is CClk
 *
 * @param[in] pConfig	           Configuration Information
 *
 * @return 	LCD_FUNC_OK   Execute successfully
 *                  LCD_FUNC_ERR  Error occurred.
 *
 **********************************************************************/
LCD_RET_CODE LCD_Init (LCD_Config_Type* pConfig)
{
	uint8_t clkdiv;

	if(pConfig == NULL)
		return LCD_FUNC_ERR;

    if(pConfig->big_endian_byte & !pConfig->big_endian_pixel)
      return LCD_FUNC_ERR;
    
	lcd_config = *pConfig;
	
	// Assign pins
	PINSEL_ConfigPin(0,4,7);
	PINSEL_ConfigPin(0,5,7);
	PINSEL_ConfigPin(0,6,7);
	PINSEL_ConfigPin(0,7,7);
	PINSEL_ConfigPin(0,8,7);
	PINSEL_ConfigPin(0,9,7);
	PINSEL_ConfigPin(1,20,7);
	PINSEL_ConfigPin(1,21,7);
	PINSEL_ConfigPin(1,22,7);
	PINSEL_ConfigPin(1,23,7);
	PINSEL_ConfigPin(1,24,7);
	PINSEL_ConfigPin(1,25,7);
	PINSEL_ConfigPin(1,26,7);
	PINSEL_ConfigPin(1,27,7);
	PINSEL_ConfigPin(1,28,7);
	PINSEL_ConfigPin(1,29,7);
    PINSEL_ConfigPin(2,0,7);
    PINSEL_ConfigPin(2,1,7);
	PINSEL_ConfigPin(2,2,7);
	PINSEL_ConfigPin(2,3,7);
	PINSEL_ConfigPin(2,4,7);
	PINSEL_ConfigPin(2,5,7);
	PINSEL_ConfigPin(2,6,7);
	PINSEL_ConfigPin(2,7,7);
	PINSEL_ConfigPin(2,8,7);
	PINSEL_ConfigPin(2,9,7);
    PINSEL_ConfigPin(2,11,7);
	PINSEL_ConfigPin(2,12,7);
	PINSEL_ConfigPin(2,13,7);
	PINSEL_ConfigPin(4,28,7);
	PINSEL_ConfigPin(4,29,7);
	
	//Turn on LCD clock
	CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE);

	// Set clock 	
	LPC_LCD->POL &= ~(0x01 << 5);
	if( pConfig->panel_clk > 0) {
        clkdiv = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / pConfig->panel_clk - 1;
	  	LPC_SC->LCD_CFG = clkdiv & 0x1F;
		LPC_LCD->POL |=(1<<26);
	}

	// init Horizontal Timing
	LCD_SetHorizontalTiming(&pConfig->hConfig);

	// Init Vertical Timing
	LCD_SetVertialTiming(&pConfig->vConfig);

	// Set Polarity
	LCD_SetPolarity(pConfig->lcd_type, &pConfig->polarity);

	if(NULL != pConfig->lcd_palette)
	{
		LCD_SetPalette(pConfig->lcd_palette);
	}

	// Set Base address
	LCD_SetBaseAddress(LCD_PANEL_UPPER, pConfig->lcd_panel_upper);
	LCD_SetBaseAddress(LCD_PANEL_LOWER, pConfig->lcd_panel_lower);

        // Setup
    LCD_CtrlSetup(pConfig);
	
    return LCD_FUNC_OK;

	
}
/*********************************************************************//**
 * @brief		Horizontal Timing Setting
 *
 * @param[in] pConfig	           Configuration Information
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_SetHorizontalTiming(LCD_HConfig_Type* pConfig)
{
	LPC_LCD->TIMH = 0; //reset TIMH before set value
	LPC_LCD->TIMH |= ((pConfig->hbp - 1)& 0xFF)<<24;
	LPC_LCD->TIMH |= ((pConfig->hfp - 1)& 0xFF)<<16;
	LPC_LCD->TIMH |= ((pConfig->hsw - 1)& 0xFF)<<8;
	LPC_LCD->TIMH |= ((pConfig->ppl/16 - 1)& 0x3F)<<2;
	lcd_hsize =  pConfig->ppl;
}

/*********************************************************************//**
 * @brief		Vertical Timing Setting
 *
 * @param[in] pConfig	           Configuration Information
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_SetVertialTiming(LCD_VConfig_Type* pConfig)
{
	LPC_LCD->TIMV = 0;  //reset TIMV value before setting
	LPC_LCD->TIMV |= ((pConfig->vbp)& 0xFF)<<24;
	LPC_LCD->TIMV |= ((pConfig->vfp)& 0xFF)<<16;
	LPC_LCD->TIMV |= ((pConfig->vsw - 1)& 0x3F)<<10;
	LPC_LCD->TIMV |= ((pConfig->lpp - 1)& 0x03FF)<<0;
	lcd_vsize =   pConfig->lpp;
}

/*********************************************************************//**
 * @brief		Polarity Setting
 *
 * @param[in] pConfig	           Configuration Information
 * @param[in] lcd_type            It can be:
 *                                                - LCD_STN_MONOCHROME
 *                                                - LCD_STN_COLOR
 *                                                - LCD_TFT
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_SetPolarity(LCD_TYPES lcd_type, LCD_POLARITY_Type* pConfig)
{
	// LCDFP pin is active LOW and inactive HIGH
    if(pConfig->invert_vsync)
        LPC_LCD->POL |= (1<<11);
    else
        LPC_LCD->POL &= ~(1<<11);        
    // LCDLP pin is active LOW and inactive HIGH
    if(pConfig->invert_hsync)
        LPC_LCD->POL |= (1<<12);
    else
        LPC_LCD->POL &= ~(1<<12);
    // data is driven out into the LCD on the falling edge
    if(pConfig->invert_panel_clock)
        LPC_LCD->POL |= (1<<13);
    else
        LPC_LCD->POL &= ~(1<<13);
	
    // active high
    if(pConfig->active_high) {
      LPC_LCD->POL &= ~(1<<14);
    }
    else
    {
      LPC_LCD->POL |= (1<<14);
    }

    LPC_LCD->POL &= ~(0x3FF <<16);
    LPC_LCD->POL |= (pConfig->cpl - 1)<<16;

    if(lcd_type == LCD_STN_COLOR || lcd_type == LCD_STN_MONOCHROME)
	LPC_LCD->POL |= (pConfig->acb & 0x1F) << 6;
    }

/*********************************************************************//**
 * @brief		Set base address of frame buffer
 *
 * @param[in] panel	          identify which panel is.
 * @param[in] pAddress          base address of the inputted panel.
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_SetBaseAddress(LCD_PANEL panel, uint32_t pAddress)
{
	// Frame Base Address doubleword aligned
    if(panel == LCD_PANEL_UPPER)
        LPC_LCD->UPBASE = pAddress & ~7UL ;
    else
        LPC_LCD->LPBASE = pAddress & ~7UL ;
}

/*********************************************************************//**
 * @brief		LCD Setup.
 *
 * @param[in] pConfig	          Configuration information.
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_CtrlSetup(LCD_Config_Type* pConfig)
{
    // disable LCD controller	
    LPC_LCD->CTRL = 0;
	
    //  bpp
    LPC_LCD->CTRL &= ~(0x07 <<1);
    LPC_LCD->CTRL |=((pConfig->lcd_bpp & 0x07)<<1);

    if(pConfig->lcd_type == LCD_TFT) {
	    LPC_LCD->CTRL |=  (0x01 << 5);  // TFT
    }
    else {
		// Color/Mono
        if(pConfig->lcd_type == LCD_STN_COLOR) {
            LPC_LCD->CTRL &= ~ (0x01 << 4);  // Color
	    }
	    else if (pConfig->lcd_type == LCD_STN_MONOCHROME) {
	        LPC_LCD->CTRL |=  (0x01 << 4);   // Mono
	     }

	    // STN/TFT
	    LPC_LCD->CTRL &= ~ (0x01 << 5);  // STN

        // Mono4/8
    	if(pConfig->lcd_mono8)
    	    LPC_LCD->CTRL |= (0x01 << 6);
    	else
    	    LPC_LCD->CTRL &= ~(0x01 << 6);

        // Single/dual
        if(pConfig->lcd_dual)
            LPC_LCD->CTRL |= (0x01 << 7);
        else
            LPC_LCD->CTRL &= ~(0x01 << 7);
	}
	
	// notmal output
	if(pConfig->lcd_bgr)
		LPC_LCD->CTRL |= (1<<8);	// BGR
	else
		LPC_LCD->CTRL &= ~(1<<8);	// RGB

        // Byte order
	if(pConfig->big_endian_byte)
	  LPC_LCD->CTRL |= (1<<9);
	else
	  LPC_LCD->CTRL &= ~(1<<9);

	// Pixel order
	if(pConfig->big_endian_pixel)
	  LPC_LCD->CTRL |= (1<<10);
	else
	  LPC_LCD->CTRL &= ~(1<<10);
	
	// disable power
	LPC_LCD->CTRL &= ~(1<<11);
}

/*********************************************************************//**
 * @brief		Enable/disable LCD Display.
 *
 * @param[in] bEna	         0: disable, 1: enable.
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_Enable (Bool bEna)
{
  volatile uint32_t i;
  if (bEna)
  {
    LPC_LCD->CTRL |= (1<<0);
    for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
    LPC_LCD->CTRL |= (1<<11);
  }
  else
  {
    LPC_LCD->CTRL &= ~(1<<11);
    for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
    LPC_LCD->CTRL &= ~(1<<0);
  }
}


/*********************************************************************//**
 * @brief		Set palette.
 *
 * @param[in] bEna	         0: disable, 1: enable.
 *
 * @return 	None.
 *
 **********************************************************************/
void LCD_SetPalette (const uint8_t* pPallete)
{
	uint32_t i;
	uint32_t size = (0x01 << bits_per_pixel[lcd_config.lcd_bpp])/2 ;
	uint32_t * pDst = (uint32_t *)LPC_LCD->PAL;
	uint32_t * pInput = (uint32_t*) pPallete;

	for (i = 0; i < size; i++)
	{
	  *pDst = *pInput;
	  pDst++;
	  pInput++;
	}
}
/*********************************************************************//**
 * @brief		Get word offset for the given pixel
 *
 * @param[in] x	     x position of input pixel
 * @param[in] y	     y position of input pixel
 *
 * @return      Offset
 *
 **********************************************************************/
uint32_t LCD_GetWordOffset(uint32_t x, uint32_t y)
{
  uint32_t pixel_num = x + y*lcd_hsize;

  return (pixel_num * bits_per_pixel[lcd_config.lcd_bpp])/32;
}
/*********************************************************************//**
 * @brief		Get bit offset for the given pixel
 *
 * @param[in] x	     x position of input pixel
 * @param[in] y	     y position of input pixel
 *
 * @return      Offset
 *
 **********************************************************************/
uint32_t LCD_GetBitOffset(uint32_t x, uint32_t y)
{
  uint32_t pixel_num;
  uint32_t ofs;
  pixel_num = x + y*lcd_hsize;
  
  ofs = (pixel_num * bits_per_pixel[lcd_config.lcd_bpp])%32;
  

⌨️ 快捷键说明

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