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

📄 tft_nt39102_dijing.c

📁 LCD驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************
**********************************************************************************
 ** Copyright:     上海闻泰电子第一产品部
 ** All Rights     Reserved.                                      
 
 ** Project Name:  T658+M50
 ** File Name:     tft_NT39102_dijing.c                                              
 ** Description:   This file contains driver for color LCD.
                   LCD type : TFT
 				   Driver IC: NT39102
 				   Dot pixcel:128*160
 				   Manufacture: 帝晶
 									 			                                
 ** Current Ver:   1.0 				                 
 ** Author:        Huangfusheng                                              
 ** DATE:          10/15/2007  
 ** Note:          
                  
                   1.可以兼容SPFD54124B
                   
 
 ** Displace Ver:  None    
 ** Author :       ***
 ** Data   :       ***
 ********************************************************************************
 ********************************************************************************/

#include "os_api.h"
#include "sci_types.h"
//#include "lcd_api.h"
#include "gpio_api.h"
#include "lcd.h"
// #include "mv3lib.h"

 #ifdef   __cplusplus
    extern   "C" 
    {
#endif

/**---------------------------------------------------------------------------*
 **                            Macro Define
 **---------------------------------------------------------------------------*/

#define	NT39102_Dijing_WIDTH	128//176
#define	NT39102_Dijing_HEIGHT	160//220
#define MP4_MAX_WIDTH	176
#define MP4_MAX_HEIGHT	144

#define OFFSET_X	0


#define LCD_USE_DMA
//Qlw 2006/11/21
extern  int LCD_GetRefreshFlag (void);
extern  uint32  udisk_plugin;
extern void dma_init(void);

extern void *LCD_GetLCDBuffer(void);

  /******************************************************************************/
//  Description:   Clear color LCD with one color
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
/******************************************************************************/
LOCAL void NT39102_Dijing_Clear(
						uint32 color	//color to fill the whole lcd.
						);
  /******************************************************************************/
//  Description:   Close the lcd.(include sub lcd.)
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL void NT39102_Dijing_Close(void);

  /******************************************************************************/
//  Description:   Enter/Exit sleep mode .
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E  NT39102_Dijing_EnterSleep(
	BOOLEAN is_sleep 	//SCI_TRUE: exter sleep mode;SCI_FALSE:exit sleep mode.
	);

/*****************************************************************************/
//  Description:    Get the lcd base information..
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
/*****************************************************************************/
LOCAL  ERR_LCD_E   NT39102_Dijing_GetInfo(
								   LCD_INFO_T *lcd_info_ptr	//lcd information struct pointer
								   );

/******************************************************************************/
//  Description:    get the important parameter for digital camera
//	Global resource dependence: 
//  Author:         Zhemin.lin
//	Note:           
/******************************************************************************/
LOCAL ERR_LCD_E  NT39102_Dijing_GetMainLcdSpec(
	LCD_SPEC_T *spec_ptr 	//spec struct pointer
	);

/*********************************************************************/
//  Description:   Initialize color LCD : NT39102_Dijing
//  Input:
//      None.
//  Return:
//      None.
//	Note:           
/*********************************************************************/
LOCAL ERR_LCD_E NT39102_Dijing_Init(void);

/******************************************************************************/
//  Description:   invalidate a rectang of in LCD
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT39102_Dijing_Invalidate(void);

/******************************************************************************/
//  Description:   Copy a retangle data from clcd_buffer to display RAM.
//                     then the rectangle display is to be refreshed
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:       
//     To improve speed, lcd is operate in HIGH SPEED RAM WRITE MODE(4
//     uint16 are write continuously always.) So, some dummy uint16 
//     should be inserted to satisfy this mode.   Please refer to spec.
/******************************************************************************/
LOCAL ERR_LCD_E NT39102_Dijing_InvalidateRect(
	uint16 left, 	//the left value of the rectangel
	uint16 top, 	//top of the rectangle
	uint16 right, 	//right of the rectangle
	uint16 bottom	//bottom of the rectangle
	);
	
/******************************************************************************/
//  Description:  for mp4 display
//	Global resource dependence: 
//  Author:  juan.zhang

/******************************************************************************/
LOCAL ERR_LCD_E NT39102_Dijing_InvalidateRectImage(
	uint16 left, 	//the left value of the rectangel
	uint16 top, 	//top of the rectangle
	uint16 right, 	//right of the rectangle
	uint16 bottom,	//bottom of the rectangle
	uint16 *buf_ptr,
	uint8  is_invert//ignore
	);
/******************************************************************************/
//  Description:   LCD go to sleep mode
//  Author:         Yingchun.li
//	Note: 
/******************************************************************************/
LOCAL NT39102_Dijing_GoSleep(void);
/******************************************************************************/
//  Description:   LCD exit sleep mode
//  Author:         Yingchun.li
//	Note: 
/******************************************************************************/
LOCAL NT39102_Dijing_ExitSleep(void);

LOCAL void main_lcd_fill_rect(uint16 left, uint16 top,uint16 right,  uint16 bottom,uint16 color);
/**---------------------------------------------------------------------------*
 **                      Function  Definitions
 **---------------------------------------------------------------------------*/
extern uint32 dma_request(uint32 chid, uint32 saddr, uint32 daddr, uint32 size, uint32 transfer_mode, uint32 size_mode);

#define NT39102_Dijing_SEND_COMMAND( c)   		{*(volatile uint16 *)0x58000000 = c;}
	
#define  NT39102_Dijing_SEND_DATA(d) 	{*(volatile uint16 *)0x58020000 = d;}
 
//#define NT39102_Dijing_sendcommand1(command, data) {*(volatile uint16 *)0x58000000 = command;*(volatile uint16 *)0x58020000 = data;}

/******************************************************************************/
//  Description:   Set the windows address to display, in this windows
//                 color is  refreshed.
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
__inline void NT39102_Dijing_set_display_window(
	uint8 left, 	// start Horizon address
	uint8 top, 		// start Vertical address
	uint8 right, 	// end Horizon address
	uint8 bottom	// end Vertical address
	)
{
	uint16 address = 0;
	NT39102_Dijing_SEND_COMMAND(0x2A);		// set colomn address
	address = left >> 8;
	NT39102_Dijing_SEND_DATA(address);
	address = left;
	NT39102_Dijing_SEND_DATA(address);
	address = right >> 8;
	NT39102_Dijing_SEND_DATA(address);
	address = right;
	NT39102_Dijing_SEND_DATA(address);
	
	NT39102_Dijing_SEND_COMMAND(0x2B);		// set Row address
	address = top >> 8;
	NT39102_Dijing_SEND_DATA(address);
	address = top;
	NT39102_Dijing_SEND_DATA(address);
	address = bottom>>8;
	NT39102_Dijing_SEND_DATA(address);
	address = bottom;
	NT39102_Dijing_SEND_DATA(address);

	NT39102_Dijing_SEND_COMMAND(0x2C);	
	Delayms(1);
}

LOCAL void NT39102_Dijing_reset(void)
{

   uint16 lcm_nv = REFPARAM_GetLCDType();
   switch(lcm_nv)

   {

      SCI_TRACE_LOW("NT39102_dijing_reset: 7370 GG3728 NT39102/HYDIS.");
	
		case TFT_NT39102_dijing:             //  add  20070918
		{

          NT39102_Dijing_SEND_COMMAND(0x11);
          NT39102_Dijing_SEND_COMMAND(0xC0);
          NT39102_Dijing_SEND_DATA(0x05);
          NT39102_Dijing_SEND_COMMAND(0xC5);
	        NT39102_Dijing_SEND_DATA(0xCE);  //D1
	        NT39102_Dijing_SEND_COMMAND(0xC6);
	        NT39102_Dijing_SEND_DATA(0x17);

         //------------gamma
          NT39102_Dijing_SEND_COMMAND(0xE0)
          NT39102_Dijing_SEND_DATA(0x00);
          NT39102_Dijing_SEND_DATA(0x01);
          NT39102_Dijing_SEND_DATA(0x0C);
          NT39102_Dijing_SEND_DATA(0x29);
          NT39102_Dijing_SEND_DATA(0x27);
          NT39102_Dijing_SEND_DATA(0x0B);
          NT39102_Dijing_SEND_DATA(0x11);
          NT39102_Dijing_SEND_DATA(0x06);
          NT39102_Dijing_SEND_DATA(0x06);
          NT39102_Dijing_SEND_DATA(0x05); 
          NT39102_Dijing_SEND_DATA(0x0E);
          NT39102_Dijing_SEND_DATA(0x0F);
          NT39102_Dijing_SEND_DATA(0x00);
          NT39102_Dijing_SEND_DATA(0x03);
          NT39102_Dijing_SEND_DATA(0x04);
          NT39102_Dijing_SEND_DATA(0x08);
          NT39102_Dijing_SEND_COMMAND(0xE1)
          NT39102_Dijing_SEND_DATA(0x06);
          NT39102_Dijing_SEND_DATA(0x1F);
          NT39102_Dijing_SEND_DATA(0x20);
          NT39102_Dijing_SEND_DATA(0x16);
          NT39102_Dijing_SEND_DATA(0x0A);
          NT39102_Dijing_SEND_DATA(0x04);
          NT39102_Dijing_SEND_DATA(0x04);
          NT39102_Dijing_SEND_DATA(0x10);
          NT39102_Dijing_SEND_DATA(0x06);
          NT39102_Dijing_SEND_DATA(0x03);
          NT39102_Dijing_SEND_DATA(0x03);
          NT39102_Dijing_SEND_DATA(0x02);
          NT39102_Dijing_SEND_DATA(0x0E);
          NT39102_Dijing_SEND_DATA(0x0D);
          NT39102_Dijing_SEND_DATA(0x05);
          NT39102_Dijing_SEND_DATA(0x05);


        //-------add-------
          NT39102_Dijing_SEND_COMMAND(0x3a); 
 	        NT39102_Dijing_SEND_DATA(0x05); 
	        NT39102_Dijing_SEND_COMMAND(0x36);                //memory data access control  (MADCTR)       
	        NT39102_Dijing_SEND_DATA(0x00); 

          NT39102_Dijing_SEND_COMMAND(0x29);

         break;
		}
		default:
		break;
			
		
    }
}

  /******************************************************************************/
//  Description:   Clear color LCD with one color
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
 //  modify:  jim.cui	2005.0728  use dma to transport data  
/******************************************************************************/
LOCAL void NT39102_Dijing_Clear(
						uint32 color	//color to fill the whole lcd.
						)
{
	uint32 i;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();

	uint16  fill_color = color;

	for(i=0; i<(NT39102_Dijing_HEIGHT ); i++)
	{

            dma_request(0, (uint32)&fill_color, (uint32)(buf_ptr + i * NT39102_Dijing_WIDTH), NT39102_Dijing_WIDTH, 
                                     1, 1);
		
	}

	NT39102_Dijing_Invalidate();
}

/******************************************************************************/
//  Description:   invalidate a rectang of in LCD
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
//  modify:  jim.cui  2005.0728  use  dma to transport data  
/******************************************************************************/
LOCAL ERR_LCD_E NT39102_Dijing_Invalidate(void)
{
	uint16 i,j;
	uint16 address = 0;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	//uint16 value;
#ifdef LCD_USE_DMA	
	//uint32  dummy_before,dummy_after;

	if(udisk_plugin)
	{
	 	SetAIT701_ByPassMode(1);
	}
	else
	{
		if (LCD_GetRefreshFlag() != TRUE )
		{
		      SCI_TRACE_LOW(" LCD_GetRefreshFlag");
			return ERR_LCD_OPERATE_FAIL ;
		}
	}	

	NT39102_Dijing_set_display_window(0, 0, NT39102_Dijing_WIDTH-1, NT39102_Dijing_HEIGHT -1);
	for(j=0; j<(NT39102_Dijing_HEIGHT ); j++)
	{

            dma_request(0, (uint32)(buf_ptr + j * NT39102_Dijing_WIDTH), 0x58020000, NT39102_Dijing_WIDTH, 
                                     1, 0);
		
	}

#else
	NT39102_Dijing_set_display_window(0, 0, NT39102_Dijing_WIDTH-1, NT39102_Dijing_HEIGHT -1);	

	for(i=0; i<(NT39102_Dijing_WIDTH * NT39102_Dijing_HEIGHT); i++)
		NT39102_Dijing_SEND_DATA( *buf_ptr++ );
		
#endif
	 if(udisk_plugin)
	 	SetAIT701_ByPassMode(0);
	return ERR_LCD_NONE;
}

/*****************************************************************************/
//  Description:    Get the lcd base information..
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
/*****************************************************************************/
LOCAL  ERR_LCD_E   NT39102_Dijing_GetInfo(
								   LCD_INFO_T *lcd_info_ptr	//lcd information struct pointer
								   )
{
	if ( PNULL == lcd_info_ptr )
	{
		return ERR_LCD_POINTER_NULL;	
	}
	
	lcd_info_ptr->r_bitmask			= 0xf800;
	lcd_info_ptr->g_bitmask			= 0x07e0;
	lcd_info_ptr->b_bitmask			= 0x001f;
	lcd_info_ptr->bits_per_pixel	= 16;
	lcd_info_ptr->contrast_min		= 0x00;
	lcd_info_ptr->contrast_max   	= 63;
	lcd_info_ptr->contrast_defaut	= 0x0A;
	
	lcd_info_ptr->lcd_width		= NT39102_Dijing_WIDTH;
	lcd_info_ptr->lcd_height	= NT39102_Dijing_HEIGHT;
	lcd_info_ptr->lcdbuff_ptr	= (void *)LCD_GetLCDBuffer();
		
	return ERR_LCD_NONE;
}

#if 0
/******************************************************************************/
//  Description:  Set start RAM address which is write to AC(Address
//                Counter) register.
//  Input:
//      left: start Horizon address of AC
//      top: start Vertical address of AC.
//  Return:
//      None.
//	Note:           
/******************************************************************************/
__inline void NT39102_Dijing_set_start_address(
	uint8 left, 
	uint8 top
	)
{
	uint16 address = 0;
		
	address = (uint16) (((top & 0xFF)<<8) | ((left & 0xFF) + OFFSET_X));
#ifndef DATA_8BIT
	NT39102_Dijing_sendcommand1(0x21, address);	// Set start RAM address (AC register)
#endif
}
#endif

/******************************************************************************/
//  Description:   Copy a retangle data from clcd_buffer to display RAM.
//                     then the rectangle display is to be refreshed
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:       
//     To improve speed, lcd is operate in HIGH SPEED RAM WRITE MODE(4

⌨️ 快捷键说明

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