📄 tft_spfd54124a.c
字号:
/********************************************************************************
**********************************************************************************
** Copyright: 上海闻泰电子第一产品部
** All Rights Reserved.
** Project Name: T658+
** File Name: tft_SPFD54124A.c
** Description: This file contains driver for color LCD.
LCD type : TFT
Driver IC: SPFD54124A
Dot pixcel:128*160
Menufacture: 伟博电子for宏尚鹰
** Current Ver: 1.0
** Author: Huangfusheng
** DATE: 10/08/2007
** Displace Ver: ***
** 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 SPFD54124A_WIDTH 128//176
#define SPFD54124A_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 SPFD54124A_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 SPFD54124A_Close(void);
/******************************************************************************/
// Description: Enter/Exit sleep mode .
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E SPFD54124A_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 SPFD54124A_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 SPFD54124A_GetMainLcdSpec(
LCD_SPEC_T *spec_ptr //spec struct pointer
);
/*********************************************************************/
// Description: Initialize color LCD : SPFD54124A
// Input:
// None.
// Return:
// None.
// Note:
/*********************************************************************/
LOCAL ERR_LCD_E SPFD54124A_Init(void);
/******************************************************************************/
// Description: invalidate a rectang of in LCD
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E SPFD54124A_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 SPFD54124A_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 SPFD54124A_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 SPFD54124A_GoSleep(void);
/******************************************************************************/
// Description: LCD exit sleep mode
// Author: Yingchun.li
// Note:
/******************************************************************************/
LOCAL SPFD54124A_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 SPFD54124A_SEND_COMMAND( c) {*(volatile uint16 *)0x58000000 = c;}
#define SPFD54124A_SEND_DATA(d) {*(volatile uint16 *)0x58020000 = d;}
//#define SPFD54124A_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 SPFD54124A_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;
SPFD54124A_SEND_COMMAND(0x2A); // set colomn address
address = left >> 8;
SPFD54124A_SEND_DATA(address);
address = left;
SPFD54124A_SEND_DATA(address);
address = right >> 8;
SPFD54124A_SEND_DATA(address);
address = right;
SPFD54124A_SEND_DATA(address);
SPFD54124A_SEND_COMMAND(0x2B); // set Row address
address = top >> 8;
SPFD54124A_SEND_DATA(address);
address = top;
SPFD54124A_SEND_DATA(address);
address = bottom>>8;
SPFD54124A_SEND_DATA(address);
address = bottom;
SPFD54124A_SEND_DATA(address);
SPFD54124A_SEND_COMMAND(0x2C);
Delayms(1);
}
LOCAL void SPFD54124A_reset(void)
{
uint16 lcm_nv = REFPARAM_GetLCDType();
switch(lcm_nv)
{
// case TFT_SPFD54124A_Weibo:
{
//sleep out
SPFD54124A_SEND_COMMAND(0x11);
Delayms(50);
//Interface Pixel Format,16bit/pixel
SPFD54124A_SEND_COMMAND(0x3A);
SPFD54124A_SEND_DATA(0x05);
//power setting
SPFD54124A_SEND_COMMAND(0xC0);
SPFD54124A_SEND_DATA(0x03);
SPFD54124A_SEND_DATA(0x05);
SPFD54124A_SEND_COMMAND(0xC5);
SPFD54124A_SEND_DATA(0xC8);
SPFD54124A_SEND_COMMAND(0xC6);
SPFD54124A_SEND_DATA(0x0a);
//gamma setting
//------------------
SPFD54124A_SEND_COMMAND(0xE0);
SPFD54124A_SEND_DATA(0x10);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x01);
SPFD54124A_SEND_COMMAND(0xE1);
SPFD54124A_SEND_DATA(0x10);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x11);
SPFD54124A_SEND_DATA(0x01);
//-----------------
SPFD54124A_SEND_COMMAND(0x0029);//display on
SPFD54124A_SEND_COMMAND(0x2a);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x7f);
SPFD54124A_SEND_COMMAND(0x2b);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x00);
SPFD54124A_SEND_DATA(0x9f);
SPFD54124A_SEND_COMMAND(0x002C);//memory write
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 SPFD54124A_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<(SPFD54124A_HEIGHT ); i++)
{
dma_request(0, (uint32)&fill_color, (uint32)(buf_ptr + i * SPFD54124A_WIDTH), SPFD54124A_WIDTH,
1, 1);
}
SPFD54124A_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 SPFD54124A_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 ;
}
}
SPFD54124A_set_display_window(0, 0, SPFD54124A_WIDTH-1, SPFD54124A_HEIGHT -1);
for(j=0; j<(SPFD54124A_HEIGHT ); j++)
{
dma_request(0, (uint32)(buf_ptr + j * SPFD54124A_WIDTH), 0x58020000, SPFD54124A_WIDTH,
1, 0);
}
#else
SPFD54124A_set_display_window(0, 0, SPFD54124A_WIDTH-1, SPFD54124A_HEIGHT -1);
for(i=0; i<(SPFD54124A_WIDTH * SPFD54124A_HEIGHT); i++)
SPFD54124A_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 SPFD54124A_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 = SPFD54124A_WIDTH;
lcd_info_ptr->lcd_height = SPFD54124A_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 SPFD54124A_set_start_address(
uint8 left,
uint8 top
)
{
uint16 address = 0;
address = (uint16) (((top & 0xFF)<<8) | ((left & 0xFF) + OFFSET_X));
#ifndef DATA_8BIT
SPFD54124A_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
// uint16 are write continuously always.) So, some dummy uint16
// should be inserted to satisfy this mode. Please refer to spec.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -