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

📄 mytest.c

📁 嵌入式开发中触摸屏的显示读写设置,可以显示文字等简单功能
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "UtilFunc.h"
#include "stdio.h"
#include "stdlib.h"
#include "XsUartDrv.h"
#include "RegCtl.h"
#include "XsGpioDrv.h"
#include "SitsangBrdRegs.h"
#include "SitsangBrdDrv.h"
#include "XsClkMgrDrv.h"
#include "XsPwmDrv.h"

//我的文件
#include "ScreenDrv.h"
#include "pixFont.h"
//#include "vgafont.h"
//#include "buffer.h"

#ifdef AUTO_TEST
#include "package.h"
#endif

#include <string.h>
#include "systypes.h"
//#define LCD_GLOBALS 1
#include "xslcdcontroller.h"
#include "screen.h"

#define Maximum(a,b) ((a)>=(b)?(a):(b))
#define Frame_Descriptor_Addr 0xa3800000

/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/

#ifndef	LCD_SIZE_TO_PAGES
#define LCD_PAGE_SIZE   8192
#define LCD_PAGE_MASK   0xFFF
#define LCD_PAGE_SHIFT  12
#define LCD_SIZE_TO_PAGES(a)	( ((a) >> LCD_PAGE_SHIFT) + ((a) & LCD_PAGE_MASK ? 1 : 0) )
#endif

unsigned GetMMUConf(void);

/* Include the picture array */
//#include "pic.c"

#define RAND_MAX1 65534
static unsigned long next = 1;

//我的缓冲区
//static char FrameBuffer[32768];
static char FrameBuffer[614448];


//void *FrameBufferP1=&FrameBuffer[0];
int rand()
{
	return ((next = next * 1103515245 + 12345) % ((unsigned long)RAND_MAX1 + 1));
}

static
void setupLcd(Panel_Info_T * infoP)
{
  int lines;

  struct lcdregs * lcdP;
  lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;

  /* Set the color mode and panel type
   */
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,oum,1);//
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,qdm,1);//
  
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,cms,0);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,sds,infoP->dualPanel);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,pas,infoP->activeDisplay);
// temp disable int.
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ldm,1);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,sfm,1);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ium,1);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,efm,1);
  /* Little endian mode
   */
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ble,0);
  /* Four pixels per clock
   */

  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,dpd,0);
  /* Disable palette DMA
   */
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,pdd,0);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,bm,1);
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,oum,0);

  /* Pixels per line
   */
// temp panelWidth - 16
  IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,ppl,infoP->panelWidth-1);
  /* Horiz sync pulse width
   */
  IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,hsw,infoP->horizSyncPW);
  /* End of line wait
   */
  IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,elw,infoP->horizELW);
  /* Start of line wait
   */
  IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,blw,infoP->horizBLW);

  /* If dual panel we split the lines for vertical lines per panel as
   * both run in parallel.
   */
  if (infoP->dualPanel)
    lines = infoP->panelHeight/2 + infoP->extraLines;
  else
    lines = infoP->panelHeight + infoP->extraLines;
  IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,lpp,lines-1);
  /* Vertical sync width
   */
  IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,vsw,infoP->vertSyncPW);
  /* End of frame wait
   */
  IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,efw,infoP->vertEFW);
  /* Start of frame wait
   */
  IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,bfw,infoP->vertBFW);

  /* AC bias for passive display
   */
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,acb,infoP->acBiasCount);
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,api,0);
  /* Set vsync polarity
   */
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,vsp,infoP->frameSyncPol);
  /* Set hsync polarity
   */
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,hsp,infoP->horizSyncPol);
  /* Set PCLK edge polarity
   */
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,pcp,infoP->clockPol);
  /* Set enable polarity
   */
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,oep,infoP->outputEnaPol);
  
//temp
  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,bpp,4);
//  IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,dpc,1);

  /* No offsets in LCD mode (single frame buffer)
   */
  
}
#define LCD_ROUND_PAGE(_a) (((unsigned)(_a)+(LCD_PAGE_SIZE-1))/LCD_PAGE_SIZE)

int allocateFrameBuffer1(void *FrameBufferP1)
{
    DM_FrameBuffer_T * frameBufferP;
	LCDFrameDescriptorT *pFD;
    UINT i;
	UINT frameBufferSize;
    int h = 640;
    int v = 480;
    struct lcdregs * lcdP;
    
    // In the case of this display, using 16 bits
    // per pixel means the palette RAM is not used.
    // Acquire a frame buffer address from the memory manager. But first compute the
    // frame buffer size.
    frameBufferSize = (h * v * (16/8) + sizeof(DM_FrameBuffer_T));
    PrintfUartDef("frameBuffer Calling \r\n");
	PrintfUartDef("frameBuffer size is %d\r\n", frameBufferSize);
	PrintfUartDef("frameBuffer address is %x-to-%x\r\n", (UINT)FrameBufferP1,((UINT)(FrameBufferP1)+614447));;
    // now move the pointer to the frame buffer to after the structure
	//frameBufferP = (DM_FrameBuffer_T*)Frame_Buffer_P;
	frameBufferP = (DM_FrameBuffer_T*)FrameBufferP1;
	PrintfUartDef("frameBufferP is 0x%x \r\n",(UINT)frameBufferP);
	frameBufferP->bufP = (unsigned short *)(frameBufferP + 1);
	PrintfUartDef("frameBufferP->bufP is 0x%x \r\n",(UINT)(unsigned short *)(frameBufferP + 1));
    frameBufferP->pixelP = (unsigned short *)(frameBufferP + 1);
    PrintfUartDef("frameBufferP->pixelP is 0x%x \r\n",(UINT)(unsigned short *)(frameBufferP + 1));
    frameBufferP->numPage = frameBufferSize;
    PrintfUartDef("framesize is %d\r\n",frameBufferSize);
        
    // Blank the buffer
    for (i=0; i < h * v; i += 2) {
      frameBufferP->pixelP[i] = (RGB565_COLOR_BLUE & 0xFFFF);
      frameBufferP->pixelP[i+1] = (RGB565_COLOR_BLUE & 0xFFFF0000) >> 16;
    }

	//setup DMA
	//pFD = (LCDFrameDescriptorT*)(Frame_Buffer_P + frameBufferSize);
	pFD = (LCDFrameDescriptorT*)Frame_Descriptor_Addr;
	pFD->FDADR = (UINT32)pFD;
    pFD->FSADR = (UINT32)frameBufferP->pixelP;
    pFD->FIDR = 0x555aaa58;             
    pFD->LDCMD = (UINT32)640*480*2; 
        
	lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
    lcdP->FDADR0 = (UINT32)pFD;
    
	PrintfUartDef("Dump DMA descriptor at 0x%x\r\n", (UINT)pFD);
	PrintfUartDef("pFD->FSADR is  0x%x\r\n", (UINT)(pFD->FSADR));
	PrintfUartDef("pFD->LDCMD is  0x%x\r\n", (UINT)(pFD->LDCMD));
	PrintfUartDef("exiting from allocation");
	
	return 1;
}

static void clearStatusReg(void)
{
  struct lcdregs * lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
  
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ber,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,abc,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iol,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iul,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iou,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iuu,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ool,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,oul,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,oou,1);
  IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ouu,1);
  
}

static void off()
{

  struct lcdregs * lcdP;
  int timeout,wasRunning;	
	lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
  timeout = 1000; // 1 second.
  wasRunning = lcdP->lccr0.len;
  
  IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,dis,0);
  if (wasRunning) {
    while(!lcdP->lcsr.lfd) {
      Util_DelayUs(1000);
      if (!timeout--) { // Workaround, also good practice anyways.
            break;
      }
    }
  }
}

void InitLcdGraphics ( )
{
    unsigned    DATA;
	DM_FrameBuffer_T *     Buffer;

⌨️ 快捷键说明

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