220 lines
4.0 KiB
C
220 lines
4.0 KiB
C
|
#include "BoardCfg.h"
|
|||
|
#include "lcd.h"
|
|||
|
|
|||
|
#if LCD_RGB
|
|||
|
u32 *LCD_Buffer = (u32 *)SDRAMM_BASE;
|
|||
|
/**
|
|||
|
* @brief SDRAM <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
void MemoryInit(void)
|
|||
|
{
|
|||
|
SDRAM_InitStructure SDRAM_InitStruct;
|
|||
|
|
|||
|
PORT->PORTP_SEL0 = 0xAAAAAAAA; // PP0-23 => ADDR0-23
|
|||
|
// PORT->PORTP_SEL1 = 0x0000AAAA;
|
|||
|
PORT->PORTP_SEL1 &= ~0x00000F0F;
|
|||
|
PORT->PORTP_SEL1 |= 0x00000A0A;
|
|||
|
|
|||
|
PORT->PORTM_SEL0 = 0xAAAAAAAA; // PM0-15 => DATA15-0
|
|||
|
PORT->PORTM_INEN = 0xFFFF;
|
|||
|
|
|||
|
PORT->PORTM_SEL1 = 0x888; // PM16 => OEN<45><4E>PM17 => WEN<45><4E>PM18 => NORFL_CSN<53><4E>PM19 => SDRAM_CSN<53><4E>PM20 => SRAM_CSN<53><4E>PM21 => SDRAM_CKE
|
|||
|
|
|||
|
SDRAM_InitStruct.CellSize = SDRAM_CELLSIZE_64Mb;
|
|||
|
SDRAM_InitStruct.CellBank = SDRAM_CELLBANK_4;
|
|||
|
SDRAM_InitStruct.CellWidth = SDRAM_CELLWIDTH_16;
|
|||
|
SDRAM_InitStruct.CASLatency = SDRAM_CASLATENCY_2;
|
|||
|
SDRAM_InitStruct.TimeTMRD = SDRAM_TMRD_3;
|
|||
|
SDRAM_InitStruct.TimeTRRD = SDRAM_TRRD_2;
|
|||
|
SDRAM_InitStruct.TimeTRAS = SDRAM_TRAS_6;
|
|||
|
SDRAM_InitStruct.TimeTRC = SDRAM_TRC_8;
|
|||
|
SDRAM_InitStruct.TimeTRCD = SDRAM_TRCD_3;
|
|||
|
SDRAM_InitStruct.TimeTRP = SDRAM_TRP_3;
|
|||
|
SDRAM_Init(&SDRAM_InitStruct);
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief RGB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
void RGBLCDInit(void)
|
|||
|
{
|
|||
|
LCD_InitStructure LCD_initStruct;
|
|||
|
|
|||
|
GPIO_Init(GPIOB, PIN12, 1, 0, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_SetBit(GPIOB, PIN12); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
PORT->PORTN_SEL0 = 0xAAAAAAAA; // GPION.0<EFBFBD><EFBFBD>15 LCD_DATA0<41><30>15
|
|||
|
PORT->PORTN_SEL1 = 0xAA;
|
|||
|
|
|||
|
LCD_initStruct.HnPixel = LCD_HDOT;
|
|||
|
LCD_initStruct.VnPixel = LCD_VDOT;
|
|||
|
LCD_initStruct.Hfp = 32;
|
|||
|
LCD_initStruct.Hbp = 44;
|
|||
|
LCD_initStruct.Vfp = 4;
|
|||
|
LCD_initStruct.Vbp = 4;
|
|||
|
LCD_initStruct.ClkDiv = LCD_CLKDIV_2; // ע<><D7A2><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA>
|
|||
|
LCD_initStruct.ClkAlways = 0;
|
|||
|
LCD_initStruct.SamplEdge = LCD_SAMPLEDGE_FALL;
|
|||
|
LCD_initStruct.HsyncWidth = LCD_HSYNC_1DOTCLK;
|
|||
|
LCD_initStruct.IntEOTEn = 1;
|
|||
|
LCD_Init(LCD, &LCD_initStruct);
|
|||
|
LCD->SRCADDR = (uint32_t)LCD_Buffer;
|
|||
|
LCD_Start(LCD);
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief ˢ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param color <EFBFBD><EFBFBD>ɫ
|
|||
|
*/
|
|||
|
void LCD_Full_Screen(u16 color)
|
|||
|
{
|
|||
|
u32 tisColor = color << 16 | color;
|
|||
|
for (u32 i = 0; i < LCD_VDOT * LCD_HDOT; i++)
|
|||
|
{
|
|||
|
LCD_Buffer[i] = tisColor;
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param val
|
|||
|
* @param pos
|
|||
|
*/
|
|||
|
void WriteByte(u32 val, u32 pos)
|
|||
|
{
|
|||
|
if (pos % 2)
|
|||
|
{
|
|||
|
pos = pos / 2;
|
|||
|
u32 temp = LCD_Buffer[pos];
|
|||
|
temp = temp & 0xffff;
|
|||
|
temp = temp | (val << 16);
|
|||
|
LCD_Buffer[pos] = temp;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pos = pos / 2;
|
|||
|
u32 temp = LCD_Buffer[pos];
|
|||
|
temp = temp & 0xffff0000;
|
|||
|
temp = temp | (val);
|
|||
|
LCD_Buffer[pos] = temp;
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>buff
|
|||
|
*
|
|||
|
* @param buff
|
|||
|
* @param pos
|
|||
|
* @param len
|
|||
|
*/
|
|||
|
void WriteBuff(u16 *buff, u32 pos, u32 len)
|
|||
|
{
|
|||
|
if (pos % 2)
|
|||
|
{
|
|||
|
WriteByte(*buff, pos);
|
|||
|
len--;
|
|||
|
buff++;
|
|||
|
pos++;
|
|||
|
}
|
|||
|
u32 *buff32 = (u32 *)buff;
|
|||
|
pos = pos / 2;
|
|||
|
for (u32 i = 0; i < len / 2; i++)
|
|||
|
{
|
|||
|
LCD_Buffer[pos + i] = buff32[i];
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
void LCD_DrawWholeLine(u32 y, u16 color)
|
|||
|
{
|
|||
|
u16 temp[LCD_HDOT];
|
|||
|
for (u32 i = 0; i < LCD_HDOT; i++)
|
|||
|
{
|
|||
|
temp[i] = color;
|
|||
|
}
|
|||
|
WriteBuff(temp, (y * LCD_HDOT), LCD_HDOT);
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param y <EFBFBD>к<EFBFBD>
|
|||
|
* @param x <EFBFBD>к<EFBFBD>
|
|||
|
* @param color <EFBFBD><EFBFBD>ɫ
|
|||
|
*/
|
|||
|
void LCD_DrawLen(u32 y, u32 x1, u32 x2, u16 *color)
|
|||
|
{
|
|||
|
|
|||
|
WriteBuff(color, (y * LCD_HDOT + x1), (x2 - x1 + 1));
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
|||
|
*
|
|||
|
* @param y
|
|||
|
* @param color
|
|||
|
*/
|
|||
|
void LCD_DrawWholeLine2(u32 y, u16 color)
|
|||
|
{
|
|||
|
|
|||
|
u16 temp[LCD_HDOT];
|
|||
|
for (u32 i = 0; i < LCD_HDOT; i++)
|
|||
|
{
|
|||
|
temp[i] = color;
|
|||
|
}
|
|||
|
LCD_DrawLen(y, 0,799, temp);
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief ˢ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param color
|
|||
|
*/
|
|||
|
void LCD_Full_Screen2(u16 color)
|
|||
|
{
|
|||
|
for (u32 i = 0; i < LCD_VDOT; i++)
|
|||
|
{
|
|||
|
LCD_DrawWholeLine(i, color);
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief LCD<EFBFBD><EFBFBD><EFBFBD>㺯<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param x
|
|||
|
* @param y
|
|||
|
* @param color
|
|||
|
*/
|
|||
|
void LCD_Draw_Point(u32 x, u32 y, u16 color)
|
|||
|
{
|
|||
|
WriteByte(color, (x + y * LCD_HDOT));
|
|||
|
}
|
|||
|
/**
|
|||
|
* @brief ˢ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㺯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param color
|
|||
|
*/
|
|||
|
void LCD_Full_Screen3(u16 color)
|
|||
|
{
|
|||
|
for (u32 i = 0; i < LCD_VDOT; i++)
|
|||
|
{
|
|||
|
for (u32 j = 0; j < LCD_HDOT; j++)
|
|||
|
{
|
|||
|
LCD_Draw_Point(j, i, color);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief RGB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻص<EFBFBD>
|
|||
|
*
|
|||
|
*
|
|||
|
*/
|
|||
|
void LCD_Handler(void)
|
|||
|
{
|
|||
|
LCD_INTClr(LCD);
|
|||
|
LCD_Start(LCD);
|
|||
|
}
|
|||
|
#else
|
|||
|
void MemoryInit(void) { ; }
|
|||
|
void RGBLCDInit(void) { ; }
|
|||
|
|
|||
|
#endif
|