#include "EFM32GG980F1024.h"
#include "ili9342.h"
#include "em_cmu.h"
#include "em_ebi.h"
#include "em_gpio.h"
#define LCD_Command_ADDR (0x84000000)
#define LCD_Data_ADDR (0x84000004)
#define X_SIZE 320
#define Y_SIZE 240
/**************************************************
*功能:向LCD发送命令
*输入:8位命令
*输出:NULL
**************************************************/
void inline LCD_WRITE_CMD(int8u CMD)
{
*(volatile int16u*)(LCD_Command_ADDR) = CMD;
}
//GUI_Context GUI_SUPPORT_AA
/**************************************************
*功能:向LCD发送数据
*输入:16位数据
*输出:NULL
**************************************************/
inline void LCD_WRITE_DATA(int16u data)
{
*(volatile int16u*)(LCD_Data_ADDR) = (int16u)data;
}
/**************************************************
*功能:读数据
*输入:NULL
*输出:16位数据
**************************************************/
inline int16u LCD_READ_DATA(void)
{
return (*(volatile int16u*)(LCD_Data_ADDR));
}
/**************************************************
*功能:读ID号
*输入:NULL
*输出:16位ID,正确返回值应该为0X9342
**************************************************/
int16u LCD_Get_ID(void)
{
int16u IDH,IDL;
LCD_WRITE_CMD(0x00D3); //ID4 =0x009342
LCD_READ_DATA(); //dummy read 假读
LCD_READ_DATA(); //IC version.
IDH=LCD_READ_DATA();//0x0093
IDL=LCD_READ_DATA();//0x0042
return((IDH<<8)|(IDL&0x00ff));
}
/**************************************************
*功能:读LCD状态
*输入:NULL
*输出:16位ID,正确返回值应该为0X9342
**************************************************/
int16u LCD_ReadStatus(void)
{
int32u S1,S2,S3,S4;
LCD_WRITE_CMD(0x09); //ID4 =0x009342
LCD_READ_DATA(); //dummy read
S1=LCD_READ_DATA(); //0x00930
S2=LCD_READ_DATA(); //0x0042
S3=LCD_READ_DATA();
S4=LCD_READ_DATA();
return(((S1<<24)&0XFFFFFF00)|((S2<<16)&0XFFFF00)|((S3<<8)&0xFF00)|(S4&0XFF));
}
/**************************************************
*功能:LCD RST BL GPIO初始化
*输入:NULL
*输出:NULL
**************************************************/
static void LCD_GpioInit (void)
{
//LCD
GPIO_PinModeSet(LRST_PIN, gpioModePushPull, 1);
GPIO_PinModeSet(LCD_BL, gpioModeWiredAndPullUp, 1);
GPIO_PinModeSet(LCD_BL, gpioModeWiredAndPullUp, 1);
}
/**************************************************
*功能:EBI初始化
*输入:NULL
*输出:NULL
*说明:把LCD挂在BANK1上,16位模式,RS挂在A0上
**************************************************/
static void LCD_EBIInit(void)
{
EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;
/* Enable clocks */
CMU_ClockEnable(cmuClock_EBI, true);
CMU_ClockEnable(cmuClock_GPIO, true);
/* Configure LCD_SELECT (EBI and LCD cannot be shared) */
GPIO_PinModeSet( gpioPortC, 12, gpioModePushPull, 1 );
/* Configure GPIO pins as push pull */
/* EBI AD9..15 */
GPIO_PinModeSet( gpioPortA, 0, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 1, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 2, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 3, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 4, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 5, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortA, 6, gpioModePushPull, 0 );
/* EBI AD8 */
GPIO_PinModeSet( gpioPortA, 15, gpioModePushPull, 0 );
/* EBI A0..17 */
GPIO_PinModeSet(gpioPortA, 12, gpioModePushPull, 0);//A0
GPIO_PinModeSet(gpioPortA, 13, gpioModePushPull, 0);//A1
// GPIO_PinModeSet(gpioPortA, 14, gpioModePushPull, 0);//A2
// GPIO_PinModeSet(gpioPortB, 9, gpioModePushPull, 0);//A3
// GPIO_PinModeSet(gpioPortB, 10, gpioModePushPull, 0);//A4
/* EBI CS1 */
GPIO_PinModeSet( gpioPortD, 10, gpioModePushPull, 1 );
/* EBI AD0..7 */
GPIO_PinModeSet( gpioPortE, 8, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 9, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 10, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 11, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 12, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 13, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 14, gpioModePushPull, 0 );
GPIO_PinModeSet( gpioPortE, 15, gpioModePushPull, 0 );
/* EBI Wen/Ren */
GPIO_PinModeSet( gpioPortF, 8, gpioModePushPull, 1 );
GPIO_PinModeSet( gpioPortF, 9, gpioModePushPull, 1 );
ebiConfig.csLines = EBI_CS1 ;
ebiConfig.banks = EBI_BANK1;
ebiConfig.mode = ebiModeD16;
ebiConfig.aLow = ebiALowA0;
ebiConfig.aHigh = ebiAHighA5;
ebiConfig.location= ebiLocation1;
ebiConfig.blEnable = false;
ebiConfig.noIdle = false;
ebiConfig.readPrefetch = false;
/* Address Setup and hold time */
ebiConfig.addrHoldCycles = 1;
ebiConfig.addrSetupCycles = 1;
/* Read cycle times */
ebiConfig.readStrobeCycles = 3; // 3
ebiConfig.readHoldCycles = 0; // 0
ebiConfig.readSetupCycles = 0; // 0
/* Write cycle times */
ebiConfig.writeStrobeCycles = 0;
ebiConfig.writeHoldCycles = 0;
ebiConfig.writeSetupCycles = 0;
/* Configure EBI */
EBI_Init(&ebiConfig);
}
/************************************************
*功能:设置光标位置
*输入:X,Y坐标
*输出:NULL
************************************************/
void LCD_SetCursor(int16u X, int16u Y)
{
if(X > X_SIZE | Y > Y_SIZE)
return ;
LCD_WRITE_CMD(0x2B);
LCD_WRITE_DATA(X>>8);
LCD_WRITE_DATA((X&0XFF));
LCD_WRITE_CMD(0x2A);
LCD_WRITE_DATA(Y>>8);
LCD_WRITE_DATA((Y&0XFF));
LCD_WRITE_CMD(0x2C);
}
/**************************************************
*功能:画 点
*输入:
*输出:NULL
**************************************************/
void DrawPixel(int16u X, int16u Y,int16u color)
{
LCD_SetCursor(Y,X);
LCD_WRITE_DATA(color);
}
/**************************************************
*功能:获取像素值
*输入:
*输出:NULL
**************************************************/
int16u Get_PixelColor(int16u X,int16u Y)
{
int16u color;
LCD_WRITE_CMD(0x2B);
LCD_WRITE_DATA(Y>>8);
LCD_WRITE_DATA((Y&0XFF));
LCD_WRITE_DATA(Y>>8);
LCD_WRITE_DATA((Y&0XFF));
LCD_WRITE_CMD(0x2A);
LCD_WRITE_DATA(X>>8);
LCD_WRITE_DATA((X&0XFF));
LCD_WRITE_DATA(X>>8);
LCD_WRITE_DATA((X&0XFF));
LCD_WRITE_CMD(0x2E);
LCD_READ_DATA();
color = (LCD_READ_DATA()>>11)<<11; //R
color |= LCD_READ_DATA()>>11; //B
color |= (LCD_READ_DATA()>>10)<<5; //G
//return ( (LCD_READ_DATA()>>11)<<11 | LCD_READ_DATA()>>11 | (LCD_READ_DATA()>>10)<<5 );
LCD_WRITE_CMD(0x2a); //x 0~319
LCD_WRITE_DATA(0x0000);
LCD_WRITE_DATA(0x0000);
LCD_WRITE_DATA(0x0001);
LCD_WRITE_DATA(0x003f);
LCD_WRITE_CMD(0x2b); //y 0~239
LCD_WRITE_DATA(0x0000);
LCD_WRITE_DATA(0x0000);
LCD_WRITE_DATA(0x0000);
LCD_WRITE_DATA(0x00ef);
return color;
}
/**************************************************
*功能:清屏
*输入:清屏颜色值
*输出:NULL
**************************************************/
void ClearScreen(int16u color)
{
unsigned int i,j;
LCD_SetCursor(0,0);
for ( i=0; i<240; i++)
{
for ( j=0; j<320; j++)
{
LCD_WRITE_DATA(color);
}
}
}
/**************************************************
*功能:填充矩形
*输入:
*输出:NULL
**************************************************/
void DrawFillRect(int16u color,int16u X1,int16u Y1,int16u X2,int16u Y2)
{
unsigned int i,j;
for( i=0; i<(Y2-Y1); i++)
{
LCD_SetCursor(Y1+i,X1);
for ( j=0; j<(X2-X1); j++)
{
LCD_WRITE_DATA(color);
}
}
}
/**************************************************
*功能:画矩形
*输入:
*输出:NULL
**************************************************/
void DrawRect(int16u color,int16u X1,int16u Y1,int16u X2,int16u
评论0