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

📄 cstn_ssd1784.c

📁 LCD驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (LCD_GetRefreshFlag() != TRUE )
		{
		      SCI_TRACE_LOW(" LCD_GetRefreshFlag");
			return ERR_LCD_OPERATE_FAIL ;
		}
	//*****************************************************

	//SCI_TRACE_LOW("tft_SSD1784.c SSD1784_InvalidateRect line%d: left = %d, top = %d, right = %d, bottom = %d", __LINE__, left, top, right,bottom);
  	left 	= (left >= SSD1784_WIDTH)    ? SSD1784_WIDTH-1 : left;
	right 	= (right >= SSD1784_WIDTH)   ? SSD1784_WIDTH-1 : right;
	top 	= (top >= SSD1784_HEIGHT)    ? SSD1784_HEIGHT-1 : top;
	bottom 	= (bottom >= SSD1784_HEIGHT) ? SSD1784_HEIGHT-1 : bottom;

	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	}
 
 	 	
	SSD1784_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.
	//dummy_after =  3 - (right % 4);	// Inserted numbers after every arrow.
	
#ifndef LCD_USE_DMA 		
	//SSD1784_set_start_address(left, top);

	//SSD1784_SEND_COMMAND(0x17); 			// send data.
       rect_width = right-left+1;
       
	for (j = top; j <= bottom; j++)
	{	

            dma_request(0, (uint32)(buf_ptr + j * SSD1784_WIDTH+left), 0x58020000, rect_width, 
                    1, 0);	
	
	}
#else

	row = bottom - top;
	column = right - left;

	//SSD1784_set_start_address(left - dummy_before, top);

	SSD1784_SEND_COMMAND(0x5c); 			// send data.

	for (i = 0; i <= row; i++)
	{	
		//for(j = 0; j<dummy_before; j++) // Insert dummy write befor real write.
			//SSD1784_SEND_DATA(0x00);
			
		for (j = 0; j <= column; j++)	// real write 
			SSD1784_SEND_DATA( *(buf_ptr + (top+i)*SSD1784_WIDTH + left+j) );
	
		//for(j=0; j<dummy_after; j++)	// Insert dummy write after real write.
			//SSD1784_SEND_DATA(0x00);
	}			
#endif
	
	return ERR_LCD_NONE;
}

/******************************************************************************/
//  Description:  for mp4 display
//	Global resource dependence: 
//  Author:  juan.zhang

/******************************************************************************/
LOCAL ERR_LCD_E SSD1784_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
	)
{
	uint32 i, j;
	uint32 dummy_before, dummy_after;
	uint32 row, column,rect_width;

  	left 	= (left >= MP4_MAX_WIDTH)    ? MP4_MAX_WIDTH-1 : left;
	right 	= (right >= MP4_MAX_WIDTH)   ? MP4_MAX_WIDTH-1 : right;
	top 	= (top >= MP4_MAX_HEIGHT)    ? MP4_MAX_HEIGHT-1 : top;
	bottom 	= (bottom >= MP4_MAX_HEIGHT) ? MP4_MAX_HEIGHT-1 : bottom;

	left = 0;
	right = 127;
	top = 0;
	bottom = 159;	//175;	

	
	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	}
 
 	SCI_TRACE_LOW("tft_SSD1784.c SSD1784_InvalidateRectImage() left=%d,right=%d,top=%d,bottom=%d,is_invert=%d line%d", left,right,top,bottom,is_invert,__LINE__); 	
 	
 	if (is_invert)
	{
		SSD1784_sendcommand1(0x17,0x0005 );
	}
	else
	{
		SSD1784_sendcommand1(0x17,0x0000 );
	}
 	 	
	SSD1784_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.
	dummy_after =  3 - (right % 4);	// Inserted numbers after every arrow.
	

#if 1	
	//	SSD1784_set_display_window(left, top, right, bottom);	
	if (is_invert)
	{
		SSD1784_set_start_address(right, top);
	}	    
	else
	{
		SSD1784_set_start_address(left, top);
	}    

	SSD1784_SEND_COMMAND(0x5c); 			// send data.

	if (is_invert)
	{
		for (j = left; j <= right; j++)  
		{		
			for (i = top; i <= bottom; i++)  
			{
				SSD1784_SEND_DATA( *(buf_ptr + j * 176 + i) ); 
			}
		}			
	}
	else
	{
		for (j = top; j <= bottom; j++)
		{
			for (i = left; i <= right; i++)
			{
				SSD1784_SEND_DATA( *(buf_ptr + j * 176 + i) );
			}
		}				
	}	
#endif
	SSD1784_SEND_COMMAND(0x5c );
	return ERR_LCD_NONE;
}
/*@Zhemin.Lin, CR9122, begin*/

static LCD_SPEC_T g_SSD1784_spec =
{
	0,		//uint8	rgb_sequence; 		/*rgb sequence*/
										/*0: R-G-B, 1: B-G-R*/
	10,		//uint8	min_cycle_read;		/*read cycle:  ns*/
	50,		//uint8	min_cycle_write;	/*write cycle: ns*/
	0,		//uint8	cyclenum_sendaddr;	/*operation cycle to send address*/
										/* 0: once, 1:twice*/
	0,		//uint8	cyclenum_senddata;	/*operation cycle to send data */
										/* 0; once, 1:twice*/
	1,		//uint8	cmd_num_setupwin;	/*command number to settint up widnow space*/
										/*0: 4 commands for setting up window space: x-start, x-end, y-start, y-end*/
										/*1: 2 commands for setting up window space: x-address, y-address*/
										/*2: 1 commanns for setting up window space window address*/
										/*3: no commands for setting up window space*/
	1,		//uint8	method_send_cmdaddr;/*how to send command & address*/
										/*0: sending together, 1:sending separately*/
	1,		//uint8	ads_is_high;		/*status of ADS when sending parameter*/
										/*0: low, 1: high*/
	0,		//uint8	sequence_cmdaddr;	/*the sequence of command & address, if not send command & address together as 16 bits*/
										/*0: write 2 window area on a 16bit bus, Hitachi*/
										/*1, write 1 sindow area with one command, Casio*/
										/*2, write 1 command and 2 parameters separately, Samsung*/
										/*3, reserved*/
										/*4, write 1 command, 2 parameters for page, 4 parameters for column, Epson*/
										/*5, write 1 command, 4 parameters for page, 2 parameters for column*/
										/*6, write 1 command, write 4 parameters for each page/column*/
	4,		//uint8	cyclenum_setupwin;	/*operation cycle to set up window*/
	1,		//uint8	method_gram_access;	/*select method to begin actul data read/write address for selected window area in GRAM*/
										/*0: without any assigning x/y address, use initial start address of window*/
										/*1: assign 1 x/y set command and parameter onto 16bit bus at onece*/
										/*2: use separate for X and Y, with upper byte consists of command and lower byte for parameter*/
										/*3, 1 command for selecting X/Y adn 2 parameters, us command and parameter separately*/
										/*4, set different command for x and y, and command and parameter differs*/
	1,		//uint8	sequence_gram_access;/*read/write command and sequence for GRAM*/
										/*0: perform read/write without seperate read/write command but by strobe 'high' ADS(RS)pin, samsung*/
										/*1: data cycle comes right afer read/write command, Toshiba/Matsushita/Hitachi/NEC*/
										/*2: after read/write command follows start address parameter for X and Y and follows data cycle, Casio*/
										/*3: similiar to 2 but sends X and Y parameters together on 16 bit BUS*/
	0,		//uint8	order_xy;			/*order of x and y address, I think, this field is active when sequence_gram_access = 2*/
										/*0: X first*/
										/*1: Y first*/
	1,		//uint8	is_dummy_read;		/*deciding first read data when reading GRAM*/
										/*0: acknowledge first data as valid data*/
										/*1: acknowledge first data as dummy data*/
	3,		//uint8	cyclenum_read;		/*total cycle numbers needed to access GRAM read/write*/
	0x15,	//uint8	win_setstartx_cmd;	/*window x start address set command*/
	0x00,	//uint8	win_setendx_cmd;	/*window x end address set command*/
	0x75,	//uint8	win_setstarty_cmd;	/*window y start address set command*/
	0x00,	//uint8	win_setendy_cmd;	/*window y end address set command*/
	0x00,	//uint8	gram_setx_cmd;		/*gram x address set command*/
	0x00,	//uint8	gram_sety_cmd;		/*gram y address set command*/
	0x5d,	//uint8	gram_read_cmd;		/*gram read command*/
	0x5c,	//uint8	gram_write_cmd;		/*gram write command*/
	//@zhemin.lin, add 1 line, CR9590
	0x08,	//uint8	line_offset;		/*line offset for display on lcd*/
	0x00	//uint8 colum_offset        /*columoffset for display on lcd*/
};


/******************************************************************************/
//  Description:    get the important parameter for digital camera
//	Global resource dependence: 
//  Author:         Zhemin.lin
//	Note:           
/******************************************************************************/
LOCAL ERR_LCD_E  SSD1784_GetMainLcdSpec(
	LCD_SPEC_T *spec_ptr 	//spec struct pointer
	)
{
	if (spec_ptr == PNULL)
	{
		return 1;
	}
	
	memcpy(spec_ptr, &g_SSD1784_spec, sizeof(LCD_SPEC_T));
	
	return ERR_LCD_NONE;
}

/******************************************************************************/
//  Description:   Enter/Exit sleep mode .
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E  SSD1784_EnterSleep(
	BOOLEAN is_sleep 	//SCI_TRUE: exter sleep mode;SCI_FALSE:exit sleep mode.
	)
{
	SCI_TRACE_LOW("SSD1784_EnterSleep,%d", is_sleep);

	if ( is_sleep ) // enter sleep mode.
	{
		SSD1784_GoSleep(); 
	}
	else 			// out sleep mode 
	{
		//SSD1784_reset();
		SSD1784_ExitSleep();
	}

	/*
	if( !GetUdiskState())
	DC_EnterSleep(is_sleep);
	*/
	return ERR_LCD_NONE;
	}


/*****************************************************************************/
//  Description:    Enable lcd to partial display mode, so can save power.
//	Global resource dependence: 
//  Author:         Jim.zhang
//  Return:         SCI_TRUE:SUCCESS ,SCI_FALSE:failed.
//	Note:           If all input parameters are 0, exit partial display mode.
/*****************************************************************************/
LOCAL ERR_LCD_E SSD1784_SetDisplayWindow(
	uint16 left, 		//left of the window
	uint16 top,			//top of the window
	uint16 right,		//right of the window
	uint16 bottom		//bottom of the window
	)
{
	SSD1784_set_display_window(left, top, right, bottom);

	//SSD1784_set_start_address(left, top);		//@David.Jia 2005.12.26

	//SSD1784_SEND_COMMAND(0x0022); 				//@David.Jia 2005.12.26

	return ERR_LCD_NONE;
}

/*********************************************************************/
//  Description:   Initialize color LCD : SSD1784
//  Input:
//      None.
//  Author:         yinchun.li
//  Return:
//      None.
//	Note:
//  modify:  jim.cui  2005.0728 add dma init  
/*********************************************************************/
LOCAL ERR_LCD_E SSD1784_Init(void)
{
	
	//dma init
	dma_init ();
	
	//SSD1784_HW_reset();
	SSD1784_reset();
	
	SSD1784_Clear( 0xf25f );
	
	return ERR_LCD_NONE;
}


/******************************************************************************/
//  Description:  set the contrast value 
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL ERR_LCD_E   SSD1784_SetContrast(
	uint16  contrast	//contrast value to set
	)
{
	return ERR_LCD_FUNC_NOT_SUPPORT;
} 


/*****************************************************************************/
//  Description:    Set the brightness of LCD.
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/*****************************************************************************/
LOCAL ERR_LCD_E   SSD1784_SetBrightness(
	uint16 brightness	//birghtness to set
	)
{
	return ERR_LCD_FUNC_NOT_SUPPORT;
}

/******************************************************************************/
//  Description:   Close the lcd.(include sub lcd.)
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
LOCAL void SSD1784_Close()
{
    GPIO_SetLcdBackLight( SCI_FALSE );
    SSD1784_EnterSleep( SCI_TRUE );	
}


LOCAL LCD_OPERATIONS_T SSD1784_operations = 
{
	SSD1784_Init,
	SSD1784_EnterSleep,
	SSD1784_SetContrast,
	SSD1784_SetBrightness,
	SSD1784_SetDisplayWindow,
	SSD1784_GetInfo,
	SSD1784_InvalidateRect,
	SSD1784_InvalidateRectImage,
	SSD1784_Invalidate,
	SSD1784_Clear,
	SSD1784_Close,
	SSD1784_GetMainLcdSpec
};

/******************************************************************************/
//  Description:  return the SSD1784 lcd driver funtion pointer
//	Global resource dependence: 
//  Author:         Jim.zhang
//	Note:
/******************************************************************************/
PUBLIC LCD_OPERATIONS_T* SSD1784_GetOperations()
{
	return &SSD1784_operations;
}

#define ADC_NUM 10
PUBLIC BOOLEAN SSD1784_Probe(void)
{
	return SCI_TRUE;
}


LOCAL SSD1784_GoSleep(void)
{

  SSD1784_SEND_COMMAND(0x95);
  SCI_TRACE_LOW("LCD:enter sleep");

}

LOCAL SSD1784_ExitSleep(void)
{

    SSD1784_SEND_COMMAND(0x94);
	SCI_TRACE_LOW("LCD:exit sleep");

}

#if 0
LOCAL void main_lcd_fill_rect(uint16 left, uint16 top,uint16 right,  uint16 bottom,uint16 color)
{
	uint16 i,j;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	for(i = top; i < bottom;i++)
	{
		for(j = left; j < right; j++)
		{                 
			*(buf_ptr+i*SSD1784_WIDTH+j)=color;
		}
	}

}


void main_lcd_test()
 {
	unsigned long i;


	//GPIO_SetLcdReset( 0 );	//lcd hardware reset.
	//for(i=0; i<3500; i++);		
	//GPIO_SetLcdReset( 1 );

	GPIO_SetLcdBackLight( SCI_TRUE );//set backlight 

	SSD1784_reset();// lcd init 

	for(i=0; i<3500; i++);
	main_lcd_fill_rect(0,0,SSD1784_WIDTH,SSD1784_HEIGHT/3,0xf800);//r
	main_lcd_fill_rect(0,SSD1784_HEIGHT/3,SSD1784_WIDTH,(2*SSD1784_HEIGHT)/3,0x07e0);//g	
	main_lcd_fill_rect(0,(2*SSD1784_HEIGHT)/3,SSD1784_WIDTH,SSD1784_HEIGHT,0x001f);//g	
	SSD1784_Invalidate();
	for(i=0; i<3500; i++);
	main_lcd_fill_rect(0,0,SSD1784_WIDTH,SSD1784_HEIGHT,0x5171);//r	

	SSD1784_InvalidateRect(0,0,20,30);
	//for(i=0; i<3500; i++); 
	//while(1);
}
#endif

/**---------------------------------------------------------------------------*
 **                         Compiler Flag                                     *
 **---------------------------------------------------------------------------*/
#ifdef   __cplusplus
    }
#endif 

⌨️ 快捷键说明

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