#include "BoardCfg.h" #include "lcd.h" #if LCD_RGB u32 *LCD_Buffer = (u32 *)SDRAMM_BASE; /** * @brief SDRAM 初始化 * */ 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、PM17 => WEN、PM18 => NORFL_CSN、PM19 => SDRAM_CSN、PM20 => SRAM_CSN、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控制器初始化 * */ void RGBLCDInit(void) { LCD_InitStructure LCD_initStruct; GPIO_Init(GPIOB, PIN12, 1, 0, 0); //背光控制 GPIO_SetBit(GPIOB, PIN12); //点亮背光 PORT->PORTN_SEL0 = 0xAAAAAAAA; // GPION.0~15 LCD_DATA0~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; // 注意手册上屏幕的时钟要求 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 刷屏函数1,写入速度最快 * * @param color 颜色 */ 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 写入数据 * * @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 快速写入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 写入整行 * */ 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 绘制一行数据 * * @param y 行号 * @param x 列号 * @param color 颜色 */ void LCD_DrawLen(u32 y, u32 x1, u32 x2, u16 *color) { WriteBuff(color, (y * LCD_HDOT + x1), (x2 - x1 + 1)); } /** * @brief 写入整行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 刷屏函数2,按行写入 * * @param color */ void LCD_Full_Screen2(u16 color) { for (u32 i = 0; i < LCD_VDOT; i++) { LCD_DrawWholeLine(i, color); } } /** * @brief LCD描点函数 * * @param x * @param y * @param color */ void LCD_Draw_Point(u32 x, u32 y, u16 color) { WriteByte(color, (x + y * LCD_HDOT)); } /** * @brief 刷屏函数3,描点函数,速度慢 * * @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发送完成中断回调 * * */ void LCD_Handler(void) { LCD_INTClr(LCD); LCD_Start(LCD); } #else void MemoryInit(void) { ; } void RGBLCDInit(void) { ; } #endif