?? tft_nt3916.c
字號:
/******************************************************************************
** 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.
******************************************************************************/
#include "os_api.h"
#include "sci_types.h"
#include "gpio_api.h"
#include "lcd.h"
#include "lcm_drv.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**---------------------------------------------------------------------------*
** Macro Define
**---------------------------------------------------------------------------*/
#define NT3916_WIDTH 176
#define NT3916_HEIGHT 220
//#define OFFSET_X 2
static uint8 OFFSET_X = 2;
extern void *LCD_GetLCDBuffer(void);
/******************************************************************************/
// Description: Clear color LCD with one color
// Global resource dependence:
// Author: louis.wei
// Note:
/******************************************************************************/
LOCAL void NT3916_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 NT3916_Close(void);
/******************************************************************************/
// Description: Enter/Exit sleep mode .
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_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 NT3916_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 NT3916_GetLcdSpec(
LCD_SPEC_T *spec_ptr //spec struct pointer
);
/*********************************************************************/
// Description: Initialize color LCD : HD66773
// Input:
// None.
// Return:
// None.
// Note:
/*********************************************************************/
LOCAL ERR_LCD_E NT3916_Init(void);
/******************************************************************************/
// Description: invalidate a rectang of in LCD
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_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 NT3916_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: Copy a retangle data from external buffer to display RAM.
// then the rectangle display is to be refreshed
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_InvalidateRect_Image(
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 //buffer pointer of the image to display
);
/******************************************************************************/
// 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 NT3916_set_start_address(
uint16 left,
uint16 top
);
/******************************************************************************/
__inline void NT3916_set_display_window(
uint16 left, // start Horizon address
uint16 right, // end Horizon address
uint16 top, // start Vertical address
uint16 bottom // end Vertical address
);
/**---------------------------------------------------------------------------*
** Function Definitions
**---------------------------------------------------------------------------*/
#if 1
#define NT3916_SEND_COMMAND(c) \
{ \
LCM_WAIT_AHBFIFO_NOTFULL \
*(volatile uint32 *)(LCM_CMD_ADDR(0,0)) = c;\
}
#define NT3916_SEND_DATA(d) \
{ \
LCM_WAIT_AHBFIFO_NOTFULL \
*(volatile uint32 *)(LCM_DATA_ADDR(0,0)) = d;\
}
#define NT3916_sendcommand1(c, d) \
{ \
LCM_WAIT_AHBFIFO_NOTFULL \
*(volatile uint32 *)(LCM_CMD_ADDR(0,0)) = c;\
*(volatile uint32 *)(LCM_DATA_ADDR(0,0)) = d;\
}
#else
#define NT3916_SEND_COMMAND(c) { LCM_SendCmd(c, 0); }
#define NT3916_SEND_DATA(d) { LCM_SendData(d, 0); }
#define NT3916_sendcommand1(command, data) { LCM_SendCmdData(command, data, 0); }
#endif
#ifdef LCM_DMA
#define NT3916_SEND_LINE_DATA(buf_ptr, pPixel) \
{ \
LCM_DMA_Write((uint32 *)buf_ptr,LCM_DATA_ADDR(0,0), pPixel * 2, DATA_SIZE_HALFWORD); \
buf_ptr += pPixel; \
}
#else
#define NT3916_SEND_LINE_DATA(buf_ptr, pPixel) \
{ \
do \
{ \
NT3916_SEND_DATA( *(buf_ptr++) ); \
pPixel--; \
}while(pPixel > 0); \
}
#endif
void Delayms (uint32 ms)
{
uint32 t1, t2;
t1 = t2 = SCI_GetTickCount ();
do{
t2 = SCI_GetTickCount ();
}while (t2 < (t1+ms));
}
PUBLIC void NT3916_SetOffset(uint8 offset)
{
OFFSET_X = offset;
}
void NT3916_reset(void)
{
NT3916_SEND_COMMAND(0x11);
LCD_Wait(10);
NT3916_SEND_COMMAND(0x20);
NT3916_SEND_COMMAND(0x38);
NT3916_SEND_COMMAND(0x13);
NT3916_SEND_COMMAND(0x3a);
NT3916_SEND_DATA(0x55);
NT3916_SEND_COMMAND(0xB6);//0000
NT3916_SEND_DATA(0x00); //C0
NT3916_SEND_DATA(0x00); //C0
NT3916_SEND_COMMAND(0x36);//0000
NT3916_SEND_DATA(0x00); //C0
NT3916_SEND_COMMAND(0x26);
NT3916_SEND_DATA(0x01);
NT3916_SEND_COMMAND(0xC7);
NT3916_SEND_DATA(0xBF);
NT3916_SEND_COMMAND(0xC0);
NT3916_SEND_DATA(0x05);
NT3916_SEND_DATA(0x05);
NT3916_SEND_COMMAND(0xC5);
NT3916_SEND_DATA(0x40);
NT3916_SEND_DATA(0x48); //38
NT3916_SEND_COMMAND(0xC6);
NT3916_SEND_DATA(0x0E);
NT3916_SEND_COMMAND(0x29);
NT3916_SEND_COMMAND(0x2C);
}
/******************************************************************************/
// Description: Clear color LCD with one color
// Global resource dependence:
// Author: louis.wei
// Note:
/******************************************************************************/
LOCAL void NT3916_Clear(
uint32 color //color to fill the whole lcd.
)
{
uint32 i;
uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
for( i=0; i<(NT3916_HEIGHT * NT3916_WIDTH); i++)
{
*buf_ptr++ = color;
}
NT3916_Invalidate();
}
#ifdef LCD_READDATA
//Test buffer
uint16 g_lcd_read_buffer[176*220];
/******************************************************************************/
// Description: Read GRAM content
// Global resource dependence:
// Author: Younger.yang
// Note:
/******************************************************************************/
//if you want to read GRAM, you should pay attention to the setting of BGR
//which will Reverse the order from R, G, B to B, G, R for GRAM data.
void NT3916_read(void)
{
uint16 *buf_ptr = 0;
uint8 left = 0,top = 0;
uint16 address = 0;
buf_ptr = g_lcd_read_buffer;
address = (uint16) ( (((NT3916_WIDTH - 1 + OFFSET_X) & 0xFF ) << 8 ) | (OFFSET_X));
NT3916_sendcommand1(0x16, address); // set horizon address
address = (uint16) ( ((NT3916_HEIGHT-1) & 0xFF) << 8 );
NT3916_sendcommand1(0x17, address); // set vertical address
// Set start RAM address (AC register)
NT3916_sendcommand1(0x21, OFFSET_X);
for(top = 0;top < (NT3916_HEIGHT); top++)
{
for(left = 0;left < (NT3916_WIDTH); left++)
{
*(volatile uint32 *)LCM_IFMODE &= ~BIT_5;//LCM_RD 0 write for M3
//NT3916_SEND_DATA(0); //LCM_RD 0 write for M2
NT3916_set_start_address(left,top);//read address(hd66773 need it)
NT3916_SEND_COMMAND(0x22);//read command
//Wait until AHB_fifo is empty
LCM_WAIT_AHBFIFO_EMPTY
*(volatile uint32 *)LCM_IFMODE |= BIT_5;//LCM_RD 1 read for M3
// NT3916_SEND_DATA(BIT_18); //LCM_RD 1 read for M2
NT3916_SEND_DATA(BIT_18); //dummy read(hd66773 need it,others maybe needn’t)
NT3916_SEND_DATA(BIT_18); //really read
//Wait until AHB_fifo is empty
LCM_WAIT_AHBFIFO_EMPTY
*buf_ptr++ = *(volatile uint32 *)LCM_RDDATA;//read data from register
}
}
//exit read,enter write mode
*(volatile uint32 *)LCM_IFMODE &= ~BIT_5;//LCM_RD 0 write for M3
//NT3916_SEND_DATA(0); //LCM_RD 0 write for M2
}
#endif
/******************************************************************************/
// Description: invalidate a rectang of in LCD
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_Invalidate(void)
{
register uint32 pPixel;
register uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
if (LCD_GetRefreshFlag() != TRUE )
{
return ERR_LCD_OPERATE_FAIL ;
}
NT3916_set_start_address (0x0, 0x0);
NT3916_set_display_window (0x0, NT3916_WIDTH - 1, 0x0, NT3916_HEIGHT -1);
NT3916_SEND_COMMAND(0x022); // send data.
pPixel = (NT3916_WIDTH) * (NT3916_HEIGHT);
NT3916_SEND_LINE_DATA(buf_ptr, pPixel);
return ERR_LCD_NONE;
}
/*****************************************************************************/
// Description: Get the lcd base information..
// Global resource dependence:
// Author: louis.wei
// Note:
/*****************************************************************************/
LOCAL ERR_LCD_E NT3916_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 = NT3916_WIDTH;
lcd_info_ptr->lcd_height = NT3916_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 NT3916_set_display_window(
uint16 left, // start Horizon address
uint16 right, // end Horizon address
uint16 top, // start Vertical address
uint16 bottom // end Vertical address
)
{
uint16 address = 0;
SCI_TRACE_LOW("NT3916_set_display_window:%d,%d,%d,%d",left,top,right,bottom);
address = (uint16) ((((right & 0xFF) + OFFSET_X)<<8) | ((left & 0xFF) + OFFSET_X));
NT3916_sendcommand1(0x2a, address); // set horizon address
address = (uint16) (((bottom & 0xFF)<<8) | (top & 0xFF));
NT3916_sendcommand1(0x2b, address); // set vertical address position
}
/******************************************************************************/
// 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 NT3916_set_start_address(
uint16 left,
uint16 top
)
{
uint16 address = 0;
address = (uint16) (((top & 0xFF)<<8) | ((left & 0xFF) + OFFSET_X));
NT3916_sendcommand1(0x30, address); // Set start RAM address (AC register)
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -