📄 lcd_lpc1788.c
字号:
that no check on the parameters needs to be performed.
*/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
/* Convert logical into physical coordinates (Dep. on LCDConf.h) */
#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
int xPhys = LOG2PHYS_X(x, y);
int yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
/* Write into hardware ... Adapt to your system */
if ((x < LCD_XSIZE) && (y < LCD_YSIZE)) {
*(volatile CPU_INT16U *)(LCD_VRAM_BASE_ADDR + 2*(xPhys + LCD_XSIZE * yPhys)) = (unsigned short)PixelIndex;
}
}
/*********************************************
*
* LCD_L0_GetPixelIndex
*
**********************************************
Purpose:
Returns the index of the given pixel. The upper layers of emWin
calling this routine make sure that the coordinates are in range, so
that no check on the parameters needs to be performed.
*/
unsigned int LCD_L0_GetPixelIndex(int x, int y) {
LCD_PIXELINDEX PixelIndex;
/* Convert logical into physical coordinates (Dep. on LCDConf.h) */
#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
int xPhys = LOG2PHYS_X(x, y);
int yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
/* Write into hardware ... Adapt to your system */
if ((x < U_LCD_XSIZE) && (y < U_LCD_YSIZE)) {
PixelIndex = *((volatile CPU_INT16U *)(LCD_VRAM_BASE_ADDR + 2*(xPhys + U_LCD_XSIZE * yPhys)));
return PixelIndex;
}
return 0;
}
/*********************************************
*
* LCD_L0_XorPixel
*
**********************************************
*/
void LCD_L0_XorPixel(int x, int y) {
LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
}
/*********************************************
*
* LCD_L0_DrawHLine
*
**********************************************
*/
void LCD_L0_DrawHLine (int x0, int y, int x1) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
for (; x0 <= x1; x0++) {
LCD_L0_XorPixel(x0, y);
}
} else {
for (; x0 <= x1; x0++) {
LCD_L0_SetPixelIndex(x0, y, LCD_COLORINDEX);
}
}
}
/*********************************************
*
* LCD_L0_DrawVLine
*
**********************************************
*/
void LCD_L0_DrawVLine (int x, int y0, int y1) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
for (; y0 <= y1; y0++) {
LCD_L0_XorPixel(x, y0);
}
} else {
for (; y0 <= y1; y0++) {
LCD_L0_SetPixelIndex(x, y0, LCD_COLORINDEX);
}
}
}
/*********************************************
*
* LCD_L0_FillRect
*
**********************************************
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
for (; y0 <= y1; y0++) {
LCD_L0_DrawHLine(x0, y0, x1);
}
}
/*********************************************
*
* LCD_L0_DrawBitmap
*
**********************************************
*/
void LCD_L0_DrawBitmap(int x0, int y0,
int xsize, int ysize,
int BitsPerPixel,
int BytesPerLine,
const U8* pData, int Diff,
const LCD_PIXELINDEX* pTrans)
{
int i;
/* Use _DrawBitLineXBPP */
for (i=0; i<ysize; i++) {
switch (BitsPerPixel) {
case 1:
_DrawBitLine1BPP(x0, i + y0, pData, Diff, xsize, pTrans);
break;
case 2:
_DrawBitLine2BPP(x0, i + y0, pData, Diff, xsize, pTrans);
break;
case 4:
_DrawBitLine4BPP(x0, i + y0, pData, Diff, xsize, pTrans);
break;
case 8:
_DrawBitLine8BPP(x0, i + y0, pData, xsize, pTrans);
break;
case 16:
DrawBitLine16BPP(x0, i + y0, (const U16 *)pData, xsize, pTrans);
break;
}
pData += BytesPerLine;
}
}
/*********************************************
*
* LCD_L0_SetOrg
*
**********************************************
*/
void LCD_L0_SetOrg(int x, int y) {
GUI_USE_PARA(x);
GUI_USE_PARA(y);
}
/*********************************************
*
* LCD_On / LCD_Off
*
**********************************************
*/
void LCD_On (void) {
#ifdef LCD_ON
volatile uint32_t i;
LPC_LCD->CTRL |= (1<<0);
for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
LPC_LCD->CTRL |= (1<<11);
#endif
}
void LCD_Off (void) {
volatile uint32_t i;
#ifdef LCD_OFF
LPC_LCD->CTRL &= ~(1<<11);
for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
LPC_LCD->CTRL &= ~(1<<0);
#endif
}
/*********************************************
*
* LCD_L0_Init
*
**********************************************
Purpose:
Initialises the LCD-controller.
*/
int LCD_L0_Init(void) {
// Assign pins
LPC_IOCON->P1_31 &= ~(0x1F); //set P1.31 GPIO
LPC_GPIO1->DIR |= (0x1<<31);
LPC_IOCON->P1_20 = 0x27;
LPC_IOCON->P1_21 = 0x27;
LPC_IOCON->P1_22 = 0x27;
LPC_IOCON->P1_23 = 0x27;
LPC_IOCON->P1_24 = 0x27;
LPC_IOCON->P1_25 = 0x27;
LPC_IOCON->P1_26 = 0x27;
LPC_IOCON->P1_27 = 0x27;
LPC_IOCON->P1_28 = 0x27;
LPC_IOCON->P1_29 = 0x27;
LPC_IOCON->P2_1 = 0x20;
LPC_IOCON->P2_2 = 0x27;
LPC_IOCON->P2_3 = 0x27;
LPC_IOCON->P2_4 = 0x27;
LPC_IOCON->P2_5 = 0x27;
LPC_IOCON->P2_6 = 0x27;
LPC_IOCON->P2_7 = 0x27;
LPC_IOCON->P2_8 = 0x27;
LPC_IOCON->P2_9 = 0x27;
LPC_IOCON->P2_13 = 0x27;
LPC_IOCON->P4_29 = 0x27;
#if (C_GLCD_BitsPP == 32)
LPC_GPIO1->CLR |= (0x1<<31);
LPC_IOCON->P0_4 = 0x27; //VD0
LPC_IOCON->P0_5 = 0x27; //VD1
LPC_IOCON->P4_28 = 0x27; //VD2
LPC_IOCON->P0_6 = 0x27; //VD8
LPC_IOCON->P0_7 = 0x27; //VD9
LPC_IOCON->P0_8 = 0x27; //VD16
LPC_IOCON->P0_9 = 0x27; //VD17
LPC_IOCON->P2_12 = 0x27; //VD18
#endif
#if (C_GLCD_BitsPP == 16)
LPC_GPIO1->CLR &= ~(0x1<<31);
LPC_IOCON->P0_4 &= ~(0x7); //VD0
LPC_IOCON->P0_5 &= ~(0x7); //VD1
LPC_IOCON->P4_28 &= ~(0x7); //VD2
LPC_IOCON->P0_6 &= ~(0x7); //VD8
LPC_IOCON->P0_7 &= ~(0x7); //VD9
LPC_IOCON->P0_8 &= ~(0x7); //VD16
LPC_IOCON->P0_9 &= ~(0x7); //VD17
LPC_IOCON->P2_12 &= ~(0x7); //VD18
#endif
/*Back light enable*/
LPC_GPIO2->DIR = (1<<1);
LPC_GPIO2->SET= (1<<1);
//Turn on LCD clock
CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE);
// Disable cursor
LPC_LCD->CRSR_CTRL &=~(1<<0);
// disable GLCD controller
LPC_LCD->CTRL = 0;
// 24 bpp
#if (C_GLCD_BitsPP == 32)
LPC_LCD->CTRL &= ~(0x07 <<1);
LPC_LCD->CTRL |=(5<<1);
#endif
#if (C_GLCD_BitsPP == 16) //16bpp 5:6:5
LPC_LCD->CTRL &= ~(0x07 <<1);
LPC_LCD->CTRL |=(0x6<<1);
#endif
// TFT panel
LPC_LCD->CTRL |= (1<<5);
// single panel
LPC_LCD->CTRL &= ~(1<<7);
// notmal output
LPC_LCD->CTRL &= ~(1<<8);
// little endian byte order
LPC_LCD->CTRL &= ~(1<<9);
// little endian pix order
LPC_LCD->CTRL &= ~(1<<10);
// disable power
LPC_LCD->CTRL &= ~(1<<11);
// init pixel clock
LPC_SC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((uint32_t)C_GLCD_PIX_CLK);
// bypass inrenal clk divider
LPC_LCD->POL |=(1<<26);
// clock source for the LCD block is HCLK
LPC_LCD->POL &= ~(1<<5);
// LCDFP pin is active LOW and inactive HIGH
LPC_LCD->POL |= (1<<11);
// LCDLP pin is active LOW and inactive HIGH
LPC_LCD->POL |= (1<<12);
// data is driven out into the LCD on the falling edge
LPC_LCD->POL |= (1<<13);
// active high
LPC_LCD->POL &= ~(1<<14);
LPC_LCD->POL &= ~(0x3FF <<16);
LPC_LCD->POL |= (C_GLCD_H_SIZE-1)<<16;
// init Horizontal Timing
LPC_LCD->TIMH = 0; //reset TIMH before set value
LPC_LCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24;
LPC_LCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16;
LPC_LCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8;
LPC_LCD->TIMH |= ((C_GLCD_H_SIZE/16) - 1)<<2;
// init Vertical Timing
LPC_LCD->TIMV = 0; //reset TIMV value before setting
LPC_LCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24;
LPC_LCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16;
LPC_LCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10;
LPC_LCD->TIMV |= C_GLCD_V_SIZE - 1;
// Frame Base Address doubleword aligned
LPC_LCD->UPBASE = LCD_VRAM_BASE_ADDR & ~7UL ;
LPC_LCD->LPBASE = LCD_VRAM_BASE_ADDR & ~7UL ;
return 0;
}
/*********************************************
*
* LCD_L0_SetLUTEntry
*
**********************************************
*/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color) {
GUI_USE_PARA(Pos);
GUI_USE_PARA(Color);
}
#else
void LCD444_c(void) { } /* avoid empty object files */
#endif /* (LCD_CONTROLLER undefined) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -