📄 lcd.c
字号:
// 2005/09/22 for test at ads liuzy
#include "lcd.h"
#include "gpio.h"
#include "memdefs.h"
#define FRAME_BUFFER_BASE_PHYSICAL FRAME_BUFFER_0_BASE_PHYSICAL
#define NULL 0
//
// Lcd
typedef struct _LCD_FRAME_DESCRIPTOR
{
unsigned int FDADR; // Pointer to next frame descriptor (Physical address)
unsigned int FSADR; // Pointer to the data (Physical address)
unsigned int FIDR; // Frame descriptor ID
unsigned int LDCMD; // DMA command
unsigned int PHYSADDR; // PHYSADDR contains the physical address of this descriptor.
}LCD_FRAME_DESCRIPTOR;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd2=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorPalette=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorTemp=NULL;
unsigned int frameBufferSize = 0;
unsigned char *gFrameBuffer = NULL; // pointer to first byte of screen memory
void ClearFrameBuffer(unsigned int color);
void LcdSetupGPIOs(void);
void InitLCDController(void);
void EnableLCDController(void);
void DisableLCDController(void);
void LCDClearStatusReg(void);
void LCDClearStatusReg()
{
// Clear the status register by writing 1's to each bit.
LCSR = ( LCD_LDD | LCD_SOF | LCD_BER | LCD_ABC | LCD_IUL |
LCD_IUU | LCD_OU | LCD_QD | LCD_EOF | LCD_BS |
LCD_SINT );
}
void ClearFrameBuffer(unsigned int color)
{
unsigned int i;
unsigned *fbp;
fbp=(unsigned *)gFrameBuffer;//+(activeFrameBuffer*frameBufferSize);
// for(i=0;i<(DispDrvr_cxScreen*DispDrvr_cyScreen*(bpp/8)/4);i++)
for(i=0;i<38400;i++)
{
// fbp++;
// fbp++;
if (color == 1)
{
*fbp++ = 0xFFFFFFFF;
// *fbp++ = 0xFFFFFFFF;
// *fbp++ = 0x44004400; // Ones turn it white
}
else
{
*fbp++ = 0x000000000; // Zeros turn it black
// *fbp++ = 0x000000000;
// *fbp++ = 0xBB00BB00;
// *fbp++ = 0x000000000;
}
}
/*
fbp += 240*30;
for(i=0;i<3840;i++)
{
// fbp++;
// fbp++;
if (color == 1)
{
// *fbp++ = 0xFFFFFFFF;
// *fbp++ = 0xFFFFFFFF;
*fbp++ = 0x11111111; // Ones turn it white
}
else
{
//*fbp++ = 0x000000000; // Zeros turn it black
// *fbp++ = 0x000000000;
*fbp++ = 0xF000F000;
// *fbp++ = 0x000000000;
}
}
fbp += 240*30;
for(i=0;i<3840;i++)
{
// fbp++;
// fbp++;
if (color == 0)
{
// *fbp++ = 0xFFFFFFFF;
// *fbp++ = 0xFFFFFFFF;
*fbp++ = 0x55555555; // Ones turn it white
}
else
{
//*fbp++ = 0x000000000; // Zeros turn it black
// *fbp++ = 0x000000000;
*fbp++ = 0x99999999;
// *fbp++ = 0x000000000;
}
}
// line 3
fbp += 240*30;
for(i=0;i<3840;i++)
{
// fbp++;
// fbp++;
if (color == 1)
{
// *fbp++ = 0xFFFFFFFF;
// *fbp++ = 0xFFFFFFFF;
*fbp++ = 0x44004400; // Ones turn it white
}
else
{
//*fbp++ = 0x000000000; // Zeros turn it black
// *fbp++ = 0x000000000;
*fbp++ = 0xBB00BB00;
// *fbp++ = 0x000000000;
}
}
*/
}
//
// 1. Configure the GPIO pins for LCD controller functionality.
//
void LcdSetupGPIOs()
{
// Program the GPDR to configure GPIO 58 through 77 as outputs
GPDR1 |= GPIO_58 | GPIO_59 | GPIO_60 | GPIO_61 | GPIO_62 | GPIO_63;
GPDR2 |= ( GPIO_64 | GPIO_65 | GPIO_66 | GPIO_67 | GPIO_68 |
GPIO_69 | GPIO_70 | GPIO_71 | GPIO_72 | GPIO_73 |
GPIO_74 | GPIO_75 | GPIO_76 | GPIO_77);
// Program the GAFR1_U to select alternate function 2 for GPIO 58 through 63.
GAFR1_U = (GAFR1_U & 0x000FFFFF) |
( GPIO_58_AF2_LDD0 | GPIO_59_AF2_LDD1 | GPIO_60_AF2_LDD2 |
GPIO_61_AF2_LDD3 | GPIO_62_AF2_LDD4 | GPIO_63_AF2_LDD5 );
// Program the GAFR2_L to select alternate function 2 for GPIO 64 through 77.
GAFR2_L = (GAFR2_L & 0xF0000000) |
( GPIO_64_AF2_LDD6 | GPIO_65_AF2_LDD7 | GPIO_66_AF2_LDD8 |
GPIO_67_AF2_LDD9 | GPIO_68_AF2_LDD10 | GPIO_69_AF2_LDD11 |
GPIO_70_AF2_LDD12 | GPIO_71_AF2_LDD13 | GPIO_72_AF2_LDD14 |
GPIO_73_AF2_LDD15 | GPIO_74_AF2_LCD_FCLK | GPIO_75_AF2_LCD_LCLK |
GPIO_76_AF2_LCD_PCLK | GPIO_77_AF2_LCD_ACBIAS );
}
//
// 2. Write the frame descriptors and, if needed, the palette descriptor to memory
// Program all of the LCD configuration registers except the Frame Descriptor Address Registers
// (FDADRx) and the LCD Controller Configuration Register 0(LCCR0).
//
void InitLCDController()
{
unsigned int PCD = 0;
unsigned int BPP = 0;
LCCR0 = 0;
LCCR1 = 0;
LCCR2 = 0;
LCCR3 = 0;
// Configure the general purpose frame descriptors
// Set the physical address of the frame descriptor
frameDescriptorCh0fd1->FDADR = LCD_FDADR(DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL);
// Set the physical address of the frame buffer
frameDescriptorCh0fd1->FSADR = LCD_FSADR(FRAME_BUFFER_BASE_PHYSICAL);
// Clear the frame ID
frameDescriptorCh0fd1->FIDR = LCD_FIDR(0);
// Set the DMA transfer length to the size of the frame buffer
frameDescriptorCh0fd1->LDCMD = LCD_Len(frameBufferSize);
// Store the physical address of this frame descriptor in the frame descriptor
frameDescriptorCh0fd1->PHYSADDR = frameDescriptorCh0fd1->FDADR;
// frameDescriptorCh0fd2 is used only if a palette load is performed.
// FBR0 is cleared and is not used.
FBR0 = 0;
// Load the contents of FDADR0 with the physical address of this frame descriptor
FDADR0 = LCD_FDADR(frameDescriptorCh0fd1->FDADR);
// Convert the bpp setting into a value that the LCD controller understands.
BPP = 4;
PCD =6;//(LCLK / (2 * TFTQVGA_PIXEL_CLOCK_FREQUENCY)) - 1;
LCCR1 = ( LCD_PPL(239) | LCD_HSW(4) | LCD_ELW(3) | LCD_BLW(7) );
LCCR2 = ( LCD_LPP(319) | LCD_VSW(2) | LCD_EFW(3) | LCD_BFW(2) );
LCCR3 = ( LCD_PCD(PCD) | LCD_ACB(0xff) | LCD_PCP | LCD_BPP(BPP) );
LCCR0 = ( LCD_OUM | LCD_BM | LCD_QDM | LCD_PAS |LCD_EFM | LCD_SFM | LCD_IUM |LCD_LDM | LCD_ENB);
// PCD = (LCLK / (2 * TFTQVGA_PIXEL_CLOCK_FREQUENCY)) - 1;
/* PCD = 7;
LCCR1 = ( LCD_PPL(319) | LCD_HSW(0x01) | LCD_ELW(0x03) | LCD_BLW(0x33) );
LCCR2 = ( LCD_LPP(239) | LCD_VSW(0x02) | LCD_EFW(0x04) | LCD_BFW(0x04) );
LCCR3 = ( LCD_PCD(PCD) | LCD_BPP(BPP) | LCD_PCP | LCD_VSP | LCD_HSP);
LCCR0 = ( LCD_LDM | LCD_SFM | LCD_IUM | LCD_EFM | LCD_PAS | LCD_BM); */
}
//
// Enable the LCD controller by writing to LCCR0
//
void EnableLCDController()
{
LCCR0 |= LCD_ENB;
}
//
// Disabliing the LCD Controller
//
void DisableLCDController()
{
// Copy the active frame buffer into a temporary buffer
// because we are going to write over the active frame buffer
// with a blank all black display. When we restore the display
// when we wake up, we want to be able to copy the original
// frame buffer back in.
// CopyFrameBuffer(1);
// Turn the display to black
// and allow a few frames to display
int i,j;
ClearFrameBuffer(0);
// msWait(100);
// delay for 100ms;
for(i=0;i<1000;i++)
for(j=0;j<1000;j++);
// Initiate power down sequence
LCCR0 |= LCD_DIS;
// Wait for LDD bit to get set once the last DMA transfer has completed
while(!(LCSR & LCD_LDD));
// Clear the sticky LDD bit
LCSR |= LCD_LDD;
}
void Main(void)
{
unsigned int color = 0;
int i,j, k;
frameBufferSize = 0x25800;
gFrameBuffer = (unsigned char*) (FRAME_BUFFER_0_BASE_PHYSICAL);
// DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_VIRTUAL
frameDescriptorCh0fd1 = (volatile LCD_FRAME_DESCRIPTOR * )(DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL);
// Initialize the GPIO registers for proper LCD Controller operation
LcdSetupGPIOs();
// Clear the frame buffer
ClearFrameBuffer(0);
// Initialize the LCD Controller and Board Control Register
InitLCDController();
// Clear LCD Controller status register
LCDClearStatusReg();
// Enable the LCD controller
EnableLCDController();
k=0;
while(1)
{
ClearFrameBuffer(color);
k++;
//GPDR1 |= GPIO_32;
//GPSR1 |= GPIO_32;
if(k>31)
k=0;
for(i=0;i<1000;i++)
for(j=0;j<1000;j++);
//GPCR1 |= GPIO_32;
//GPSR1 |= GPIO_32;
if((color == 1) && (k >30) )
color = 0;
else if(k>30)
color = 1;
}
DisableLCDController();
//gFrameBuffer = (unsigned char *)(FRAME_BUFFER_0_BASE_PHYSICAL);
}
//frameBufferSize = 0x25800; //bpp / 8 * DispDrvr_cxScreen * DispDrvr_cyScreen;
//(16/8 * 240*320 = 153600);
//frameDescriptorCh0fd1 = (volatile LCD_FRAME_DESCRIPTOR *)VirtualAllocCopy(sizeof(LCD_FRAME_DESCRIPTOR), "DispDrvrInitialize : lcdFrameDescriptor", (PVOID)(DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_VIRTUAL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -