📄 at91display.c
字号:
/**----------------------------------------------------------------------------*//** ATMEL Microcontroller Software Support - ROUSSET -*//**----------------------------------------------------------------------------*//** The software is delivered "AS IS" without warranty or condition of any*//** kind, either express, implied or statutory. This includes without*//** limitation any warranty or condition with respect to merchantability or*//** fitness for any particular purpose, or against the infringements of*//** intellectual property rights of others.*//**----------------------------------------------------------------------------*//** File Name : main.c*//** Object : main application written in C*//** Creation : FB 13/01/2003*//** 1.1 31/03/03 JPP : Add DBGU message *//**----------------------------------------------------------------------------*/#include "vxWorks.h"#include "ics1523.h"#include "s1d13806.h"#include "AT91RM9200.h"#include "lib_AT91RM9200.h"#include "h/drv/display/at91Display.h"/* Master Clock */#define MCK_KHz 60000 /**************************************************************************************//* Externals*//**************************************************************************************/#include "ics1523.c"#include "s1d13806.c"/** Function in init.c*/typedef unsigned short WORD;typedef unsigned long DWORD;typedef unsigned char BYTE;typedef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved;} RGBQUAD;#if 0#define Transparent 1typedef struct { long TotalVmem; // Total video memory on the card. int Width; // Width (in pixels) of the mode. int Height; // Height (in pixels) of the mode. int ColorDepth; // Bits per pixel. int Stride; // Number of bytes from one line to the next. WORD BytesPerPixel; // 1,2 for 8BPP,15/16BPP } CONTROL_INFO,*LPCONTROL_INFO;//---------------------------------------------------------------------------//// BLT Info//// The structure sent as an argument to all Blt routines.////---------------------------------------------------------------------------typedef struct { int ROP; int SrcTop; int SrcLeft; int SrcWidth; int SrcHeight; int DstTop; int DstLeft; int DstWidth; int DstHeight; int PatternX,PatternY; int Attribute; DWORD ColorBg; DWORD ColorFg; } BLT_INFO,*LPBLT_INFO;static CONTROL_INFO Control;#endif#define LCD 0x01#define CRT 0x02#define TV 0x04/**************************************************************************************//* Global variables*//**************************************************************************************//** Image data buffer declaration*//*static char image_buf[ ( H_MAX_RES * V_MAX_RES * 3 ) + BMP_HEADER_SIZE ] ;*//** Message buffer*/char MsgBuffer[256];int gDisplayDef = Display_Def_0;int gDisplayCfg = TFT_CRT_Display_Conf;/*CRT_Display_Conf;*//**----------------------------------------------------------------------------*//** \fn AT91F_FillDisplayMemory*//** \brief Fill display memory by filling 1.25 MB Display Memory*//**----------------------------------------------------------------------------*/__inline void AT91F_FillDisplayMemory(void){ char* buf ; int i; short* disp_mem = (short *) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with 0xFF*/ buf = ( char * ) S1D13806_DISP_MEM_BASE ; for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 ) ; i++, buf++ ) { if ( ( i < ( int ) ( ( ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ) - ( display_def_desc.hdw * 2 * 5 ) ) ) || ( i > ( int ) ( ( ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ) + ( display_def_desc.hdw * 2 * 5 ) ) ) ) *buf = 0xFF ; else *buf = 0x00 ; } /** Fill display memory by filling 1.25 MB Display Memory with Green*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = GREEN_WORD_MASK ; disp_mem = ( short * ) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with Blue*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = BLUE_WORD_MASK ; disp_mem = ( short * ) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with Red*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = RED_WORD_MASK ; disp_mem = ( short * ) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with Green + Blue*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = ( GREEN_WORD_MASK | BLUE_WORD_MASK ) ; disp_mem = ( short * ) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with Red + Blue*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = ( RED_WORD_MASK | BLUE_WORD_MASK ) ; disp_mem = ( short * ) S1D13806_DISP_MEM_BASE ; /** Fill display memory by filling 1.25 MB Display Memory with Green + Red*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 )/2 ; i++, disp_mem++ ) *disp_mem = ( GREEN_WORD_MASK | RED_WORD_MASK ) ; buf = ( char * ) S1D13806_DISP_MEM_BASE ; /** Clear display memory by filling 1.25 MB Display Memory with 0*/ for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 2 ) ; i++, buf++ ) *buf = 0x00 ; buf = ( char * ) S1D13806_DISP_MEM_BASE ; for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 4 ) ; i++, buf++ ) *buf = 0x00 ; buf = ( char * ) S1D13806_DISP_MEM_BASE ;/* for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw * 4 ) ; i++, buf++ ) image_buf[i] = *buf ;*/}/**----------------------------------------------------------------------------*//** \fn main*//** \brief *//**----------------------------------------------------------------------------*/STATUS at91_s1d1xInit(){ char message[64]; int i,ack ; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; /* Configure PIO A to periph mode for IrDA problem of consumption*/ /* Not associated to the configuration of Memory Display Controller*/ AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA, /* PIO controller base address*/ ((unsigned int) AT91C_PA23_TXD2), /* Peripheral A */ 0); /* Peripheral B */ /* Disable pullup*/ AT91F_PIO_CfgOutput(AT91C_BASE_PIOA,AT91C_PA23_TXD2); AT91C_BASE_PIOA->PIO_PPUDR =AT91C_PA23_TXD2; /*////////////////////////////////////////////////////////////////////////////////*/ /* Init PIO for Memory Display Controller */ AT91F_PIO_CfgPeriph( AT91C_BASE_PIOC, ((unsigned int) AT91C_PC6_NWAIT) ,0 ); /* Init Static Memory Controller SMC2 for Memory Display Controller (EBI->SMC2->NCS2)*/ /* Setup NCS2 for Memory Display Controller (EBI->SMC2) */ /* Specific configuration for AT91RM9200EK */#ifdef __EK__ /* Initialization of the Static Memory Controller for Chip Select 3 , ADD WAIT STATE 5 */ AT91_SYS->EBI_SMC2_CSR[3] = (AT91C_SMC2_NWS & 0x5) | AT91C_SMC2_WSEN | (AT91C_SMC2_TDF & 0x100) | AT91C_SMC2_DBW;#else AT91_SYS->EBI_SMC2_CSR[2] = (AT91C_SMC2_NWS & 0x4) | AT91C_SMC2_WSEN | (AT91C_SMC2_TDF & 0x100) | AT91C_SMC2_DBW;#endif #if 0 AT91F_DBGU_Printk("\n\r-I- ==================================================\n\r"); AT91F_DBGU_Printk("-I- AT91RM9200 Epson Embedded Memory Display Controller Test\n\r"); AT91F_DBGU_Printk("-I- --------------------------------------------------------\n\r"); /* System Timer initialization*/ AT91F_ST_SetPeriodIntervalTimer(AT91C_BASE_ST, 0x3); /* period <=> 100us*/ AT91F_ST_EnableIt(AT91C_BASE_ST, AT91C_ST_PITS); AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, /* AIC base address*/ AT91C_ID_SYS, /* System peripheral ID*/ AT91C_AIC_PRIOR_HIGHEST, /* Max priority*/ AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, /* Level sensitive*/ AT91F_ST_ASM_HANDLER ); /* Enable ST interrupt*/ AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);#endif /* ICS1523 Clock Generator Initialisation*/ ack = AT91F_ICS1523_Init ( (unsigned int) Clock_Conf, (unsigned int) MCK_KHz) ; if ( ack == (int) ICS1523_ACCESS_OK ) sprintf (message, " \n\rICS1523 Clock Generator Init OK\n\r" ) ; else if ( ack == (int) ICS1523_ACCESS_ERROR ) sprintf (message, " \n\rICS1523 Clock Generator Init failed\n\r" ) ; /** Epson S1D13806 Initialisation FOR A CRT Monitor !!!!!!!!!!!*/ AT91F_S1D13806_Init ( s1d13806_base, S1D13806_DISP_MEM_BASE, (unsigned int) CRT_Display_Conf, (unsigned int) gDisplayDef, (unsigned int) Char_Def_0, (unsigned int) MCK_KHz ) ; #if 0 /** Fill Display Memory*/ AT91F_FillDisplayMemory(); /** Display Strings*/ for ( i = 0 ; i < ( ( ( ( ( ( display_def_desc.hdw * display_def_desc.vdw * 2 ) / 16 ) / 16 ) / 8 ) + 2 ) * 4 ) ; i++ ) { sprintf (message," Test OK ! %04d",i); AT91F_S1D13806_16bpp_print_string ( s1d13806_base, message ) ; } /** Display Last String*/ sprintf ( message, " Auto Test Finished ") ; AT91F_S1D13806_16bpp_print_string ( s1d13806_base, message ) ;#endif/*while(1);*/}/*-------------------------------------------------------------------------*//*** _DisplayFifo()** ** Description: Turns display FIFO on or off*/static void _DisplayFifo(BOOL activate) { unsigned val; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; BYTE byte = s1d13806_base->S1D13806_OnChipReg.OCR_DM&0x7;if (byte == 0x00 || byte == 0x01) /*/if (_ActiveImageSurface->DisplayMode & LCD)*/ { val = s1d13806_base->S1D13806_OnChipReg.OCR_LCDDM ;/*/seReadRegByte(REG_LCD_DISPLAY_MODE);*/ if (activate) val &= ~0x80; else val |= 0x80; s1d13806_base->S1D13806_OnChipReg.OCR_LCDDM = val; /*/seWriteRegByte(REG_LCD_DISPLAY_MODE, val);*/ } else //if (_ActiveImageSurface->DisplayMode & (CRT | TV)) { val = s1d13806_base->S1D13806_OnChipReg.OCR_CRTDM ;/*/seReadRegByte(REG_CRTTV_DISPLAY_MODE);*/ if (activate) val &= ~0x80; else val |= 0x80; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDM = val ; /*/seWriteRegByte(REG_CRTTV_DISPLAY_MODE, val);*/ } }void seDisplayBlank(BOOL activate) { _DisplayFifo(!activate); }int displayClear(){ DWORD* buf ; int i; /*/DOWRD* disp_mem = (short *) S1D13806_DISP_MEM_BASE ;*/ AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; int lcd_start_address = 0, crt_start_address = 0; s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_2 = ( char ) ( lcd_start_address >> 16 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_1 = ( char ) ( lcd_start_address >> 8 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_0 = ( char ) lcd_start_address ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_2 = ( char ) ( crt_start_address >> 16 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_1 = ( char ) ( crt_start_address >> 8 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_CRTDBA_0 = ( char ) crt_start_address ; /** Fill display memory by filling 1.25 MB Display Memory with 0xFF*/ buf = ( DWORD * ) S1D13806_DISP_MEM_BASE ; for ( i = 0 ; i < ( int ) ( display_def_desc.hdw * display_def_desc.vdw )/2 ; i++, buf++ ) { *buf = 0x0000 ; } }void _WriteLut(int DisplayMode, BYTE *pLUT, int count){ int idx, rgb; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; if (DisplayMode == LCD) s1d13806_base->S1D13806_OnChipReg.OCR_LUTM = 1;/*/ seWriteRegByte(REG_LUT_MODE, 0x01); *//* write to LCD LUT */ else if ((DisplayMode == CRT) || (DisplayMode == TV)) s1d13806_base->S1D13806_OnChipReg.OCR_LUTM = 2; /*/seWriteRegByte(REG_LUT_MODE, 0x02); *//* write to CRT/TV LUT */ else s1d13806_base->S1D13806_OnChipReg.OCR_LUTM = 0 ;/*/seWriteRegByte(REG_LUT_MODE, 0x00); *//* write to LCD and CRT/TV LUT */ s1d13806_base->S1D13806_OnChipReg.OCR_LUTBA = 0 ;/*/seWriteRegByte( REG_LUT_ADDR, 0 );*/ for (idx = 0; idx < count; idx++) { for (rgb = 0; rgb < 3; rgb++) s1d13806_base->S1D13806_OnChipReg.OCR_LUTD = *pLUT++ ;/*/seWriteRegByte( REG_LUT_DATA, *pLUT++ );*/ }}void WriteLut(unsigned surface, BYTE *pLUT, int count){ unsigned regDisplayMode; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; regDisplayMode =s1d13806_base->S1D13806_OnChipReg.OCR_DM&0x7; if(regDisplayMode<=1) { if (surface == 0) _WriteLut(LCD, pLUT, count); //seWriteLcdLut(pLut, count); }else if((regDisplayMode&1)==0 ) { if (surface == 0) { if (regDisplayMode & TV) _WriteLut(TV, pLUT, count); // seWriteTvLut(pLut, count); else _WriteLut(CRT, pLUT, count); //seWriteCrtLut(pLut, count); } }else { if (surface == 0) { _WriteLut(LCD, pLUT, count); //seWriteLcdLut(pLut, count); _WriteLut(CRT, pLUT, count); //seWriteCrtLut(pLut, count); } }}int displayString(char* message ){ AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; AT91F_S1D13806_16bpp_print_string ( s1d13806_base, message ) ; return 0;}long __pow(int x,int y){ int i=0; long s=1; if(y>0) { for(i=0;i<y;i++) { s*=x; } } return s;}int displayBmp(int x, int y, char* szfile){ char buf[BMP_HEADER_SIZE+2]; AT91S_S1D13806_BitmapDesc bmp; AT91PS_S1D13806_BitmapDesc pBmp=&bmp; int i, j, k ; char *display_mem ; char *disp_src,*disp_buf; int dataSize=0; AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE; int lcd_start_address = 0, crt_start_address = 0; BYTE LUT[256*3]; FILE *f = fopen(szfile,"r"); if(!f) return -1; fread((char*)&bmp.type ,1, 2,f); fread((char*)&bmp.FileSize ,1, BMP_HEADER_SIZE-2,f); dataSize = pBmp->width*(pBmp->BitsPerPixel/8 ); disp_buf= (char*)malloc(dataSize); s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_2 = ( char ) ( lcd_start_address >> 16 ) ; s1d13806_base->S1D13806_OnChipReg.OCR_LCDDBA_1 = ( char ) ( lcd_start_address >> 8 ) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -