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

📄 tft_nt39102.c

📁 LCD驱动代码
💻 C
📖 第 1 页 / 共 3 页
字号:

	address = (uint16) ( ((NT39102_HEIGHT-1) & 0xFF) << 8 );
	NT39102_sendcommand1(0x2b, address); 	//  set vertical  address
*/	

	NT39102_set_display_window(0, 0, NT39102_WIDTH - 1, NT39102_HEIGHT-1);	
	NT39102_sendcommand1(0x0037, OFFSET_X);	

   	NT39102_SEND_COMMAND(0x002C); 			// send data.

	dummy_before =  1 % 4;		// Inserted numbers befor every arrow.
	dummy_after =  3 - (NT39102_WIDTH % 4);	// Inserted numbers after every arrow.

	for(j=0; j<(NT39102_HEIGHT ); j++)
	{
			
		for (i = 0; i < NT39102_WIDTH; i++)	// real write 
		{
			NT39102_SEND_DATA( *(buf_ptr + j * NT39102_WIDTH + i) );
		}
		
	}
#else
	address = (uint16) ( (((NT39102_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));	
	NT39102_sendcommand1(0x44, address);		// set horizon address

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

	// Set start RAM address (AC register)
	
	NT39102_sendcommand1(0x21, OFFSET_X);	

	NT39102_SEND_COMMAND(0x0022); 			// send data.
	
	for(i=0; i<(NT39102_WIDTH * NT39102_HEIGHT); i++)
		NT39102_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   NT39102_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_WIDTH;
       lcd_info_ptr->lcd_height                  = NT39102_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:
/******************************************************************************/
LOCAL void NT39102_set_display_window(
	uint8 left, 	// start Horizon address
	uint8 right, 	// end Horizon address
	uint8 top, 		// start Vertical address
	uint8 bottom	// end Vertical address
	)
{
	NT39102_SEND_COMMAND(0x2a);
	NT39102_SEND_DATA(0x00);
	NT39102_SEND_DATA(left&0xFF);
	NT39102_SEND_DATA(0x00);
	NT39102_SEND_DATA(right&0xFF);

	NT39102_SEND_COMMAND(0x2b);
	NT39102_SEND_DATA(0x00);
	NT39102_SEND_DATA(top&0xFF);
	NT39102_SEND_DATA(0x00);
	NT39102_SEND_DATA(bottom&0xFF);

}


/******************************************************************************/
//  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:           
/******************************************************************************/
LOCAL void NT39102_set_start_address(
	uint8 left, 
	uint8 top
	)
{
	uint16 address = 0;
		
	address = (uint16) (((top & 0xFF)<<8) | ((left & 0xFF) + OFFSET_X));
	NT39102_sendcommand1(0x37, 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.
/******************************************************************************/
LOCAL ERR_LCD_E NT39102_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,k;
	uint32 dummy_before, dummy_after;
	uint32 row, column;
	uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
	
	//SCI_TRACE_LOW("NT39102_InvalidateRect:%d,%d,%d,%d",left,top,right,bottom);

  	left 	= (left >= NT39102_WIDTH)    ? NT39102_WIDTH-1 : left;
	right 	= (right >= NT39102_WIDTH)   ? NT39102_WIDTH-1 : right;
	top 	= (top >= NT39102_HEIGHT)    ? NT39102_HEIGHT-1 : top;
	bottom 	= (bottom >= NT39102_HEIGHT) ? NT39102_HEIGHT-1 : bottom;

	if ( ( right < left ) || ( bottom < top ) )
	{
		//SCI_TRACE_LOW(" NT39102_invalidate_rect wrong: right > left or bottom > top");
		return ERR_LCD_PARAMETER_WRONG;
	}
 
 	 	
	NT39102_set_display_window(left, right, top, 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		
	NT39102_set_start_address(left, top);

	NT39102_SEND_COMMAND(0x2c); 			// send data.


	for (j = top; j <= bottom; j++)
	{	
			
		for (i = left; i <= right; i++)	// real write 
		{
			NT39102_SEND_DATA( *(buf_ptr + j * NT39102_WIDTH + i) );
		}
	
	}
#else

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

	NT39102_set_start_address(left - dummy_before, top);

	NT39102_SEND_COMMAND(0x22); 			// send data.

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

/******************************************************************************/
//  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_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,k;
	uint32 row, column;
	
  	left 	= (left >= NT39102_WIDTH)    ? NT39102_WIDTH-1 : left;
	right 	= (right >= NT39102_WIDTH)   ? NT39102_WIDTH-1 : right;
	top 	= (top >= NT39102_HEIGHT)    ? NT39102_HEIGHT-1 : top;
	bottom 	= (bottom >= NT39102_HEIGHT) ? NT39102_HEIGHT-1 : bottom;

       SCI_TRACE_LOW("NT39102_InvalidateRect:%d,%d,%d,%d",left,top,right,bottom);
	   
	if ( ( right < left ) || ( bottom < top ) )
	{
		return ERR_LCD_PARAMETER_WRONG;
	} 


	if (is_invert)
	{
		NT39102_sendcommand1(0x0036,0x0060);
		NT39102_SEND_COMMAND(0x2a);
		NT39102_SEND_DATA(0);
		NT39102_SEND_DATA(left);
		NT39102_SEND_DATA(0);
		NT39102_SEND_DATA(MP4_MAX_WIDTH+left-1);

		NT39102_SEND_COMMAND(0x2b);
		NT39102_SEND_DATA(0);
		NT39102_SEND_DATA(top);
		NT39102_SEND_DATA(0);
		NT39102_SEND_DATA(MP4_MAX_HEIGHT+top-1);
	}
	else
	{
		NT39102_sendcommand1(0x0036,0x0000);	
	}
	
	NT39102_set_display_window(left, right, top, bottom);

	if (is_invert)
	{
	    NT39102_set_start_address(right, top);
	}
	else
	{
	    NT39102_set_start_address(left, top);
	}

	NT39102_SEND_COMMAND(0x2c); 			// send data.

       if (is_invert)
       {
		for (j = left; j <= right; j++)
		{	
			for (i = top; i <= bottom; i++)	// real write 
			{
				NT39102_SEND_DATA( *(buf_ptr + j * MP4_MAX_WIDTH + i) );
			}
		}
       }
	else
	{
		for (j = top; j <= bottom; j++)
		{	
			for (i = left; i <= right; i++)	// real write 
			{
				NT39102_SEND_DATA( *(buf_ptr + j * MP4_MAX_HEIGHT + i) );
			}
		}	
	}

	if (is_invert)
	{
		NT39102_sendcommand1(0x0036,0x0000);
	}
	
	return ERR_LCD_NONE;
}

/*@Zhemin.Lin, CR9122, begin*/

static LCD_SPEC_T g_NT39102_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*/
	0x2a,	//uint8	win_setstartx_cmd;	/*window x start address set command*/
	0x00,	//uint8	win_setendx_cmd;	/*window x end address set command*/
	0x2b,	//uint8	win_setstarty_cmd;	/*window y start address set command*/
	0x00,	//uint8	win_setendy_cmd;	/*window y end address set command*/
	0x37,	//uint8	gram_setx_cmd;		/*gram x address set command*/
	0x00,	//uint8	gram_sety_cmd;		/*gram y address set command*/
	0x2c,	//uint8	gram_read_cmd;		/*gram read command*/

⌨️ 快捷键说明

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