📄 hwdrv_lcd.c
字号:
// drv_lcd.c v1.0 2004/01/06
//---------------------------------------------------------------------------------
//
// Copyright (C) SEIKO EPSON CORP. 2003
//
// GROUP : SEE LSI
// FILE : drv_lcd.c
// MODULE : Lcd driver
// Function description : Lcd driver for 320*240 QVGA LCD of S1C33L05 DMT
// Revision history :
// Date userName Description
// 2004/01/06 Hellen Yao start
//
// Notes :
//
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Include files (#include)
//---------------------------------------------------------------------------------
#include "../include/cBType.h"
#include "../include/drv_lcd.h"
//#define PANEL_XMIRROR
//#define PANEL_YMIRROR
#define COLOR_PANEL
void lcd_startDMA(U32 src_buf_adr, U32 des_buf_adr, U32 count, U32 mode);
//---------------------------------------------------------------------------------
// Global & static variables
//---------------------------------------------------------------------------------
U32 cur_vram_working_addr; //current background vram address
U32 cur_vram_lcdc_addr; //current foreground vram address
//---------------------------------------------------------------------------------
// Function name :_init_lcdc()
// Function description :This function is the initialization of the LCD
//
// Parameters
// Input :intColor:set Color/Mono type of LCD
// Output :None
// I/O :None
//
// Return value :None
//
// Global variable :MONO_4BIT,COLOR_8BIT_F2
//---------------------------------------------------------------------------------
void _init_lcdc(unsigned char lcdclkdt){
int i;
unsigned char dt;
//set P15, P16 as GPIO
*(volatile unsigned short*) 0x402d4&= 0x9f;
//set P15 as output port (as LCDPWR of C33L05)
SET_P15_H;
SET_P15_O;
//set P16 as output port (as display on)
SET_P16_H;
SET_P16_O;
//share pins of LCD : PB function select:FPDAT7--0
PB_FUNC1_LCDC;
PB_FUNC2_LCDC;
//share pins of LCD : PC function select:DRDY, FPSHIFT, FPLINE, FPFRAME
PC_FUNC_LCDC;
// 2. LCDC CLG enable: D7=1
//LCDC clock divider ratio:(D3--0)=fosc3/16=pclk=3MHz
for (i=1; i<16; i*=2)
{
dt = lcdclkdt & i;
dt = (*(volatile unsigned char*) 0x300f34 ) & ~i | dt;
*(volatile unsigned char*) 0x300f2f = 0x96; //remove write protection
*(volatile unsigned char*) 0x300f34 = dt;
};
*(volatile unsigned char*) 0x300f2f = 0x96; //remove write protection
*(volatile unsigned char*) 0x300f34 = lcdclkdt;
/* ------ LCDC initialization ------- */
// 3) 16bpp, lut bypass, dither mode
*(volatile unsigned short*) 0x380200 = 0x55; //set mode0:16bpp, lut bypass, dither mode
// 3) mono, 4bit
#ifdef COLOR_PANEL
// SET_CTRL_MODE1 = color type
*(volatile unsigned short*)0x380202 = COLOR_8BIT_F2; //set mode1
#else
// SET_CTRL_MODE1 = mono type
*(volatile unsigned short*)0x380202 = MONO_4BIT; //set mode1
#endif
//set hndp, hdp, vndp, vdp
//SET_HNDP_COUNT;
*(volatile unsigned short*) 0x380040 = 0x05; //set hndp count : (hndp+4)*8=72
//SET_VNDP_COUNT;
*(volatile unsigned short*) 0x38004a = 0x06; //set vndp count : vndp = 6
// SET_CHAR_COUNT;
*(volatile unsigned short*) 0x380042 = SCREEN_WIDTH / 8 - 1; //set horizontal panel size = 320
// SET_LINE_COUNT;
*(volatile unsigned short*) 0x38004c = SCREEN_HEIGHT - 1; //set vertical panel size = 240
//6) set screen start address
cur_vram_lcdc_addr=(U32)VRAM_ADDR_1;
cur_vram_working_addr=(U32)VRAM_ADDR_2;
// SET VRAM_ADDR_1 as current display memory
if (cur_vram_lcdc_addr > 0x3fffff)
*(volatile unsigned short*) 0x380210 = ((cur_vram_lcdc_addr - 0x2000000) / 32) | 0x8000;
else
*(volatile unsigned short*) 0x380210 = ((cur_vram_lcdc_addr - 0x3c0000) / 2) & 0x7fff;
//7) PS (Normal)
POWER_NORMAL;
// cur_vram_lcdc_addr=(U32)VRAM_ADDR_2;
// cur_vram_working_addr=(U32)VRAM_ADDR_1;
}
//---------------------------------------------------------------------------------
// Function name :lcd_startDMA()
// Function description :This function enable HSDMA ch.1 between two memories.
//
// Parameters
// Input :src_buf_adr:the address of the source memory
// des_buf_adr:the address of the destination memory
// count:the transfer count of HSDMA
// Output :None
// I/O :None
//
// Return value :None
//
// Global variable :None
//---------------------------------------------------------------------------------
void lcd_startDMA(U32 src_buf_adr, U32 des_buf_adr, U32 count, U32 mode){
//set transfer counter[15:0] = count(if single/successive transfer mode)
//set address mode:dual addr
count|= 0x80000000;
*(volatile unsigned long*) 0x48230 = count;
//set source addr(increase addr with no init, half word)
src_buf_adr|= mode & 0xf0000000;
*(volatile unsigned long*) 0x48234 = src_buf_adr;
//set destination addr(successive mode, increase addr with no init)
des_buf_adr|= mode * 0x10;
*(volatile unsigned long*) 0x48238 = des_buf_adr;
//enable HSDMA
*(volatile unsigned char*) 0x4823c|=0x01;
//enable software trigger
*(volatile unsigned char*) 0x4029a=0x02;
//detect DMA end
while (*(volatile unsigned char*) 0x4823c&0x01 != 0x00);
}
//---------------------------------------------------------------------------------
// Function name :lcd_FillRect()
// Function description :This function fill a rectangle according to input location and display color pattern.
//
// Parameters
// Input :x,y: specified the left-up position where the image will be placed, start from 0
// width: specified the image width
// height: specified the image height
// buffer: the buffer contains the image data
// Output :None
// I/O :None
//
// Return value :None
//
// Global variable :cur_vram_lcdc_addr, SCREEN_WIDTH, SCREEN_HEIGHT, LCD_BPP_UNIT
//---------------------------------------------------------------------------------
void lcd_FillRect( S16 x, S16 y, S16 width, S16 height, U16 ColorPattern){
// operating memory is cur_vram_lcdc_addr
U32 offsetPos;
U32 srcbufAdr, desbufAdr;
int i;
#ifdef PANEL_XMIRROR
x = SCREEN_WIDTH - x - 1;
#else
x = x;
#endif
#ifdef PANEL_YMIRROR
y = SCREEN_HEIGHT - y - 1;
#else
y = y;
#endif
offsetPos = SCREEN_WIDTH*y + x;
srcbufAdr = (U32)&ColorPattern;
#ifdef PANEL_XMIRROR
desbufAdr = cur_vram_lcdc_addr + (offsetPos - width + 1) * LCD_BPP_UNIT;
#else
desbufAdr = cur_vram_lcdc_addr + offsetPos * LCD_BPP_UNIT;
#endif
for (i=0; i<height; i++){
lcd_startDMA(srcbufAdr, desbufAdr, width, FIX_DMA);
#ifdef PANEL_YMIRROR
desbufAdr-=SCREEN_WIDTH*LCD_BPP_UNIT;
#else
desbufAdr+=SCREEN_WIDTH*LCD_BPP_UNIT;
#endif
}
}
//Abel
void lcd_DrawNow()
{
lcd_startDMA(cur_vram_lcdc_addr, cur_vram_working_addr, 320*240, NORMAL_DMA);
}
//abel 2004.04.26
void lcd_SetHLine( S16 x, S16 y, S16 width, U16 *buffer)
{
// operating memory is cur_vram_lcdc_addr
U32 offsetPos;
U32 srcbufAdr, desbufAdr;
int i;
#ifdef PANEL_XMIRROR
x = SCREEN_WIDTH - x - 1;
#else
x = x;
#endif
#ifdef PANEL_YMIRROR
y = SCREEN_HEIGHT - y - 1;
#else
y = y;
#endif
offsetPos = SCREEN_WIDTH*y + x;
srcbufAdr = (U32)buffer;
desbufAdr = cur_vram_lcdc_addr + offsetPos * LCD_BPP_UNIT;
#ifdef PANEL_XMIRROR
lcd_startDMA(srcbufAdr, desbufAdr, width, INVERSE_DMA);
#else
lcd_startDMA(srcbufAdr, desbufAdr, width, NORMAL_DMA);
#endif
}
void lcd_GetHLine( S16 x, S16 y, S16 width, U16 *buffer)
{
// operating memory is cur_vram_lcdc_addr
U32 offsetPos;
U32 srcbufAdr, desbufAdr;
int i;
#ifdef PANEL_XMIRROR
x = SCREEN_WIDTH - x - width;
#else
x = x;
#endif
#ifdef PANEL_YMIRROR
y = SCREEN_HEIGHT - y - 1;
#else
y = y;
#endif
offsetPos = SCREEN_WIDTH*y + x;
srcbufAdr = cur_vram_lcdc_addr + offsetPos * LCD_BPP_UNIT;
#ifdef PANEL_XMIRROR
desbufAdr = (U32)buffer + (width - 1) * LCD_BPP_UNIT;
#else
desbufAdr = (U32)buffer;
#endif
#ifdef PANEL_XMIRROR
lcd_startDMA(srcbufAdr, desbufAdr, width, INVERSE_DMA);
#else
lcd_startDMA(srcbufAdr, desbufAdr, width, NORMAL_DMA);
#endif
}
//---------------------------------------------------------------------------------
// Function name :lcd_SetImage()
// Function description :This function draw image according to input location, size and data buffer
//
// Parameters
// Input :x,y: specified the left-up position where the image will be placed, start from 0
// width: specified the image width
// height: specified the image height
// buffer: the buffer contains the image data
// Output :None
// I/O :None
//
// Return value :None
//
// Global variable :cur_vram_lcdc_addr, SCREEN_WIDTH, LCD_BPP_UNIT
//---------------------------------------------------------------------------------
void lcd_SetImage( S16 x, S16 y, S16 width, S16 height, U16 *buffer, U32 BufLen) {
// operating memory is cur_vram_lcdc_addr
U32 offsetPos;
U32 srcbufAdr, desbufAdr;
int i;
#ifdef PANEL_XMIRROR
x = SCREEN_WIDTH - x - 1;
#else
x = x;
#endif
#ifdef PANEL_YMIRROR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -