lvgl-v8/UART/SimplUART/APP/lcd.c

271 lines
5.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "BoardCfg.h"
#include "lcd.h"
#if LCD_RGB
u32 *LCD_Buffer = (u32 *)SDRAMM_BASE;
/**
* @brief SDRAM <20><>ʼ<EFBFBD><CABC>
*
*/
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<47><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*
*/
void RGBLCDInit(void)
{
LCD_InitStructure LCD_initStruct;
GPIO_Init(GPIOB, PIN12, 1, 0, 0); //<2F><><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; // 32
LCD_initStruct.Hbp = 44; // 44
LCD_initStruct.Vfp = 4; // 4
LCD_initStruct.Vbp = 4; // 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 ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>д<EFBFBD><D0B4><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD>
*
* @param color <20><>ɫ
*/
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 д<><D0B4><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 <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>buff
*
* @param buff
* @param pos
* @param len
*/
void WriteBuff(u16 *buff, u32 pos, u32 len)
{
if (pos % 2)
{
WriteByte(*buff, pos);
len--;
buff++;
pos++;
}
#if 1
pos = pos / 2;
register u32 *buff32 = (u32 *)buff;
register u32 *lcdBuff32 = LCD_Buffer;
lcdBuff32 = lcdBuff32 + pos;
// Printf("lcdBuff32:%d,buff32:%d", lcdBuff32, buff32);
for (register u32 i = 0; i < len / 2; i++)
{
lcdBuff32[i] = buff32[i];
// lcdBuff32[pos++] = *(buff32++);
// *lcdBuff32++ = buff32[i];
// *lcdBuff32++ = *buff32++;
// *lcdBuff32++ = buff32[i];
// *buff32++;
}
// u16 *temp = (u16*)buff32;
#else
pos = pos / 2;
// u32 *from = (u32 *)buff;
// u32 *to = (u32 *)&LCD_Buffer[pos];
register u32 *buff32 = (u32 *)buff;
register u32 *lcdBuff32 = LCD_Buffer;
lcdBuff32 += pos;
register u32 i=0;
u32 count = len / 2;
// Printf("len:%d,pos:%d\n", len, pos);
u32 n = (count + 7) / 8;
switch (count % 8)
{
case 0:
do
{
lcdBuff32[i] = buff32[i];i++;
case 7:
lcdBuff32[i] = buff32[i];i++;
case 6:
lcdBuff32[i] = buff32[i];i++;
case 5:
lcdBuff32[i] = buff32[i];i++;
case 4:
lcdBuff32[i] = buff32[i];i++;
case 3:
lcdBuff32[i] = buff32[i];i++;
case 2:
lcdBuff32[i] = buff32[i];i++;
case 1:
lcdBuff32[i] = buff32[i];i++;
} while (--n > 0);
;
}
#endif
}
/**
* @brief д<><D0B4><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 <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param y <20>к<EFBFBD>
* @param x <20>к<EFBFBD>
* @param color <20><>ɫ
*/
void LCD_DrawLen(u32 y, u32 x1, u32 x2, u16 *color)
{
WriteBuff(color, (y * LCD_HDOT + x1), (x2 - x1 + 1));
}
/**
* @brief д<><D0B4><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 ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
*
* @param color
*/
void LCD_Full_Screen2(u16 color)
{
for (u32 i = 0; i < LCD_VDOT; i++)
{
LCD_DrawWholeLine(i, color);
}
}
/**
* @brief LCD<43><44><EFBFBD><E3BAAF>
*
* @param x
* @param y
* @param color
*/
void LCD_Draw_Point(u32 x, u32 y, u16 color)
{
WriteByte(color, (x + y * LCD_HDOT));
}
/**
* @brief ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><E3BAAF><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><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<47><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻص<CFBB>
*
*
*/
void LCD_Handler(void)
{
LCD_INTClr(LCD);
LCD_Start(LCD);
}
void LCD_Flash_LCD()
{
LCD_Start(LCD);
}
#else
void MemoryInit(void) { ; }
void RGBLCDInit(void) { ; }
#endif