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

📄 tft_s1033.c

📁 ARMSTM32 lcd驱动程序集锦
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 ** File Name:     cstn_pcf8833.c                                             *
 ** Description:															  *
 **    This file contains driver for color LCD.(CSTN)						  *
 ** Author:         Jim zhang                                                 *
 ** DATE:           03/01/2004                                                *
 ** Copyright:      2004 Spreatrum, Incoporated. All Rights Reserved.         *
 ** Description:                                                              *
 ******************************************************************************

 ******************************************************************************
 **                        Edit History                                       *
 ** ------------------------------------------------------------------------- *
 ** DATE           NAME             DESCRIPTION                               *
 ** 02/04/2004     louis.wei	    Create.
 ** 11/15/2005     David.Jia        Modify for GG3728 (S1033/HYDIS).         *
 ** 11/22/2005     David.Jia        Modify ADC value in Probe; Entersleep code*
 ** 12/09/2005     David.Jia        Implemetation SetDisplayWindow function.  *
 ** 12/26/2005	   David.Jia		Deal can't DC preview on S1033 LCD.	  *
 ** 03/03/2006     David.Jia        cr42033, LCD ADC range changed: HX8309,   *
 **     200-230; S1033, 231-249; S1D19105, 250-280.                          *
 ******************************************************************************/

#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	S1033_WIDTH	128//176
#define	S1033_HEIGHT	160//220
#define MP4_MAX_WIDTH	176
#define MP4_MAX_HEIGHT	144

#define OFFSET_X	0

//@David.Jia 2005.11.22
#define ADC_S1033_LOW    231
#define ADC_S1033_HIGH   249           //@David.Jia 2006.3.3 cr42033

#define LCD_USE_DMA
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 S1033_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 S1033_Close(void);

  /******************************************************************************/
//  Description:   Enter/Exit sleep mode .
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E  S1033_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   S1033_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  S1033_GetMainLcdSpec(
	LCD_SPEC_T *spec_ptr 	//spec struct pointer
	);

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

/******************************************************************************/
//  Description:   invalidate a rectang of in LCD
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E S1033_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 S1033_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 S1033_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 S1033_GoSleep(void);
/******************************************************************************/
//  Description:   LCD exit sleep mode
//  Author:         Yingchun.li
//	Note: 
/******************************************************************************/
LOCAL S1033_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 S1033_SEND_COMMAND( c)   		{*(volatile uint16 *)0x58000000 = c;}
	
#define  S1033_SEND_DATA(d) 	{*(volatile uint16 *)0x58020000 = d;}
 
#define S1033_sendcommand1(command, data) {*(volatile uint16 *)0x58000000 = command;*(volatile uint16 *)0x58020000 = data;}


//LOCAL void S1033_HW_reset(void)
//{
//	GPIO_SetLcdReset(0);
//	Delayms(10);
//	GPIO_SetLcdReset(1);
//	Delayms(10);
//}

LOCAL void S1033_reset(void)
{
	SCI_TRACE_LOW("S1033_reset: 7370 GG3728 S1033/HYDIS.");
	S1033_sendcommand1(0x0000, 0x0001);
	Delayms(20);

	S1033_sendcommand1(0x0007, 0x0027); //added
	Delayms(30);
	S1033_sendcommand1(0x0010, 0x0000); 
	Delayms(30);

	S1033_sendcommand1(0x0011, 0x0210); 

	S1033_sendcommand1(0x0012, 0x0000); 
	Delayms(30);

	S1033_sendcommand1(0x0013, 0x080e); 
	Delayms(30);  //0x08,0x0c

	S1033_sendcommand1(0x0014, 0x2517); 
	Delayms(30);  //0x09,0x19  //06 16

	S1033_sendcommand1(0x0010, 0x1910); 
	Delayms(30);//

	S1033_sendcommand1(0x0013, 0x081e); 
	Delayms(100);

	S1033_sendcommand1(0x0001, 0x090C); 

	S1033_sendcommand1(0x0002, 0x0200); 

	S1033_sendcommand1(0x0003, 0x1030); 

	S1033_sendcommand1(0x0008, 0x0503); 

	S1033_sendcommand1(0x000B, 0x0000); 

	S1033_sendcommand1(0x000C, 0x0000); 

	S1033_sendcommand1(0x0030, 0x0300); 

	S1033_sendcommand1(0x0031, 0x0003); 

	S1033_sendcommand1(0x0032, 0x0000); 

	S1033_sendcommand1(0x0033, 0x0200); 

	S1033_sendcommand1(0x0034, 0x0300); 

	S1033_sendcommand1(0x0035, 0x0003); 

	S1033_sendcommand1(0x0036, 0x0000); 

	S1033_sendcommand1(0x0037, 0x0002); 

	S1033_sendcommand1(0x0038, 0x0a00); 

	S1033_sendcommand1(0x0040, 0x0000); 

	S1033_sendcommand1(0x0042, 0x9F00); 

	S1033_sendcommand1(0x0043, 0x0000); 

	S1033_sendcommand1(0x0044, 0x7F00); 

	S1033_sendcommand1(0x0045, 0x9F00); 
	Delayms(30);

	S1033_sendcommand1(0x0007, 0x0001); 
	Delayms(30);

	S1033_sendcommand1(0x0007, 0x0021); 

	S1033_sendcommand1(0x0007, 0x0023); 
	Delayms(30);

	S1033_sendcommand1(0x0007, 0x1037); 

	S1033_sendcommand1(0x0021, 0x0000); 

	S1033_SEND_COMMAND(0x0022); 
	Delayms(30);
}

  /******************************************************************************/
//  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 S1033_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<(S1033_HEIGHT ); i++)
	{

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

	S1033_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 S1033_Invalidate(void)
{
	uint16 i,j;
	uint16 address = 0;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	
#ifdef LCD_USE_DMA	
	uint32  dummy_before,dummy_after;

	
	address = (uint16) ( (((S1033_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));
	S1033_sendcommand1(0x44, address);		// set horizon address
	address = (uint16) ( ((S1033_HEIGHT-1) & 0xFF) << 8 );

	S1033_sendcommand1(0x45, address);	// set vertical address
	S1033_sendcommand1(0x0021, OFFSET_X);	
	S1033_SEND_COMMAND(0x0022); 			// send data.

	dummy_before =  1 % 4;		// Inserted numbers befor every arrow.
	dummy_after =  3 - (S1033_WIDTH % 4);	// Inserted numbers after every arrow.
        
	for(j=0; j<(S1033_HEIGHT ); j++)
	{

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

#else
	SCI_TRACE_LOW("tft_S1033.c S1033_Invalidate line%d", __LINE__);
	
	address = (uint16) ( (((S1033_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));	
	S1033_sendcommand1(0x44, address);		// set horizon address


	address = (uint16) ( ((S1033_HEIGHT-1) & 0xFF) << 8 );
	S1033_sendcommand1(0x45, address);	// set vertical address

	// Set start RAM address (AC register)	
	S1033_sendcommand1(0x21, OFFSET_X);	
	S1033_SEND_COMMAND(0x0022); 			// send data.
	
	for(i=0; i<(S1033_WIDTH * S1033_HEIGHT); i++)
		S1033_SEND_DATA( *buf_ptr++ );
		
#endif
		
	return ERR_LCD_NONE;
}

/*****************************************************************************/
//  Description:    Get the lcd base information..
//	Global resource dependence: 
//  Author:         louis.wei
//	Note:
/*****************************************************************************/
LOCAL  ERR_LCD_E   S1033_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		= S1033_WIDTH;
	lcd_info_ptr->lcd_height	= S1033_HEIGHT;
	lcd_info_ptr->lcdbuff_ptr	= (void *)LCD_GetLCDBuffer();
		
	return ERR_LCD_NONE;
}

/******************************************************************************/
//  Description:   Set the windows address to display, in this windows
//                 color is  refreshed.
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
__inline void S1033_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;

	address = (uint16) ((((right & 0xFF) + OFFSET_X)<<8) | ((left & 0xFF) + OFFSET_X));
	S1033_sendcommand1(0x44, address);		// set horizon address
	address = (uint16) (((bottom & 0xFF)<<8) | (top & 0xFF));
	S1033_sendcommand1(0x45, address);	// set vertical address
}


/******************************************************************************/
//  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 S1033_set_start_address(
	uint8 left, 
	uint8 top
	)
{
	uint16 address = 0;
		
	address = (uint16) (((top & 0xFF)<<8) | ((left & 0xFF) + OFFSET_X));
	S1033_sendcommand1(0x21, address);	// Set start RAM address (AC register)
}

/******************************************************************************/
//  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.
//  modify:  jim.cui  2005.0728  use  dma to transport data  
/******************************************************************************/

LOCAL ERR_LCD_E S1033_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
	)
{
	uint32 i, j;
	uint32 dummy_before, dummy_after;
	uint32 row, column,rect_width;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	
    //SCI_TRACE_LOW("tft_S1033.c S1033_InvalidateRect line%d: left = %d, top = %d, right = %d, bottom = %d", __LINE__, left, top, right,bottom);
  	left 	= (left >= S1033_WIDTH)    ? S1033_WIDTH-1 : left;
	right 	= (right >= S1033_WIDTH)   ? S1033_WIDTH-1 : right;
	top 	= (top >= S1033_HEIGHT)    ? S1033_HEIGHT-1 : top;
	bottom 	= (bottom >= S1033_HEIGHT) ? S1033_HEIGHT-1 : bottom;

	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	}
 
 	 	
	S1033_set_display_window(left, top, right, bottom);
	
	// In High Speed RAM Write Mode. Maybe some dummy data are insterted.
	dummy_before =  (left) % 4;		// Inserted numbers befor every arrow.

⌨️ 快捷键说明

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