summaryrefslogtreecommitdiff
path: root/bsp/lpc178x/drivers
diff options
context:
space:
mode:
author[email protected] <[email protected]>2012-04-16 04:16:19 +0000
committer[email protected] <[email protected]>2012-04-16 04:16:19 +0000
commit0982f6e079b7a23a53e6f7212908a75383f0fa3e (patch)
tree8771a9ac5553c7f04dd6442891ecb03c1f2b057e /bsp/lpc178x/drivers
parent50955197d5e80adcd029f330ce5e2e1c9ab1a598 (diff)
Added LCD driver and enable SDRAM.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2077 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp/lpc178x/drivers')
-rw-r--r--bsp/lpc178x/drivers/SConscript10
-rw-r--r--bsp/lpc178x/drivers/board.c6
-rw-r--r--bsp/lpc178x/drivers/board.h31
-rw-r--r--bsp/lpc178x/drivers/drv_glcd.c668
-rw-r--r--bsp/lpc178x/drivers/drv_glcd.h111
-rw-r--r--bsp/lpc178x/drivers/emac.c2
-rw-r--r--bsp/lpc178x/drivers/lpc17xx_lcd.c82
-rw-r--r--bsp/lpc178x/drivers/sdram.c278
-rw-r--r--bsp/lpc178x/drivers/sdram.h8
-rw-r--r--bsp/lpc178x/drivers/uart.c2
10 files changed, 1167 insertions, 31 deletions
diff --git a/bsp/lpc178x/drivers/SConscript b/bsp/lpc178x/drivers/SConscript
index 80dff26c0f..b5a9b36b11 100644
--- a/bsp/lpc178x/drivers/SConscript
+++ b/bsp/lpc178x/drivers/SConscript
@@ -1,15 +1,11 @@
-import copy
-Import('RTT_ROOT')
-Import('rtconfig')
from building import *
-cwd = GetCurrentDir()
-src = Glob('*.c')
+cwd = GetCurrentDir()
+src = Glob('*.c')
# remove no need file.
if GetDepend('RT_USING_LWIP') == False:
- src_need_remove = ['emac.c'] # need remove file list.
- SrcRemove(src, src_need_remove)
+ SrcRemove(src, 'emac.c')
CPPPATH = [cwd]
diff --git a/bsp/lpc178x/drivers/board.c b/bsp/lpc178x/drivers/board.c
index 787f0ad645..0564a1ccc2 100644
--- a/bsp/lpc178x/drivers/board.c
+++ b/bsp/lpc178x/drivers/board.c
@@ -21,6 +21,7 @@
#include "board.h"
#include "LPC177x_8x.h"
#include "system_LPC177x_8x.h"
+#include "sdram.h"
/**
* @addtogroup LPC17xx
@@ -69,16 +70,13 @@ void rt_hw_board_init()
NVIC_SetPriority(PendSV_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
rt_hw_uart_init();
- rt_console_set_device( CONSOLE_DEVICE );
-
- rt_kprintf("\r\n\r\nSystemInit......\r\n");
+ rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#if LPC_EXT_SDRAM == 1
{
SDRAM_Init();
}
#endif
-
}
/*@}*/
diff --git a/bsp/lpc178x/drivers/board.h b/bsp/lpc178x/drivers/board.h
index 38937d362b..b20597036f 100644
--- a/bsp/lpc178x/drivers/board.h
+++ b/bsp/lpc178x/drivers/board.h
@@ -18,27 +18,28 @@
#include "LPC177x_8x.h"
-/* whether use board external SDRAM memory */
-// <e>Use external SDRAM memory on the board
-// <i>Enable External SDRAM memory
-#define LPC_EXT_SDRAM 0
-// <o>Begin Address of External SDRAM
-// <i>Default: 0x60000000
-#define LPC_EXT_SDRAM_BEGIN 0xA0000000 /* the begining address of external SDRAM */
-// <o>End Address of External SDRAM
-// <i>Default: 0x60000000
-#define LPC_EXT_SDRAM_END 0xA4000000 /* the end address of external SDRAM */
-// </e>
+// <RDTConfigurator URL="http://www.rt-thread.com/eclipse">
-/* RT_USING_UART */
-#define RT_UART_RX_BUFFER_SIZE 64
+// <integer name="LPC_EXT_SDRAM" description="Enable External SDRAM memory" default="0" />
+#define LPC_EXT_SDRAM 1
+// <integer name="LPC_EXT_SDRAM" description="Begin Address of External SDRAM" default="0xA0000000" />
+#define LPC_EXT_SDRAM_BEGIN 0xA0000000
+// <integer name="LPC_EXT_SDRAM_END" description="End Address of External SDRAM" default="0xA4000000" />
+#define LPC_EXT_SDRAM_END 0xA4000000
+
+// <bool name="RT_USING_UART0" description="Using UART0" default="true" />
#define RT_USING_UART0
+// <bool name="RT_USING_UART1" description="Using UART1" default="true" />
//#define RT_USING_UART1
+// <bool name="RT_USING_UART2" description="Using UART2" default="true" />
//#define RT_USING_UART2
-#define CONSOLE_DEVICE "uart0"
-#define FINSH_DEVICE_NAME CONSOLE_DEVICE
+// <string name="RT_CONSOLE_DEVICE_NAME" description="The device name for console" default="uart" />
+#define RT_CONSOLE_DEVICE_NAME "uart0"
+
+// </RDTConfigurator>
+#define FINSH_DEVICE_NAME RT_CONSOLE_DEVICE_NAME
void rt_hw_board_init(void);
#endif
diff --git a/bsp/lpc178x/drivers/drv_glcd.c b/bsp/lpc178x/drivers/drv_glcd.c
new file mode 100644
index 0000000000..e4893305cc
--- /dev/null
+++ b/bsp/lpc178x/drivers/drv_glcd.c
@@ -0,0 +1,668 @@
+/*************************************************************************
+ *
+* Used with ICCARM and AARM.
+ *
+ * (c) Copyright IAR Systems 2008
+ *
+ * File name : drv_glcd.c
+ * Description : Graphical LCD driver
+ *
+ * History :
+ * 1. Date : 6, March 2008
+ * Author : Stanimir Bonev
+ * Description : Create
+ *
+ *
+ * $Revision: 24636 $
+ *
+ * @Modify: NXP MCU Application Team - NguyenCao
+ * @Date: 04. March. 2011
+ **************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+//#include "ConstGlbPtrs.h"
+//#include "Ex_sdram.h"
+#include "drv_glcd.h"
+#include "lpc177x_8x_clkpwr.h"
+#include "lpc177x_8x_pinsel.h"
+
+//#include "Cursor.h"
+//#include "logo.h"
+
+//#define MHZ
+
+#define C_GLCD_CLK_PER_LINE (C_GLCD_H_SIZE + C_GLCD_H_PULSE + C_GLCD_H_FRONT_PORCH + C_GLCD_H_BACK_PORCH)
+#define C_GLCD_LINES_PER_FRAME (C_GLCD_V_SIZE + C_GLCD_V_PULSE + C_GLCD_V_FRONT_PORCH + C_GLCD_V_BACK_PORCH)
+#define C_GLCD_PIX_CLK (C_GLCD_CLK_PER_LINE * C_GLCD_LINES_PER_FRAME)
+
+//LPC_LCD_TypeDef * const g_pLCD = ((LPC_LCD_TypeDef*) LPC_LCD_BASE);
+//LPC_SC_TypeDef * const g_pSC = ((LPC_SC_TypeDef*) LPC_SC_BASE);
+
+#define SDRAM_BASE 0xA0000000 /* CS0 */
+#define SDRAM_BASE_ADDR SDRAM_BASE
+
+#define LCD_VRAM_BASE_ADDR ((unsigned long)SDRAM_BASE_ADDR + 0x00000000)
+#define LCD_CURSOR_BASE_ADDR ((unsigned long)0x20088800)
+
+
+static pFontType_t pCurrFont = NULL;
+static LdcPixel_t TextColour;
+static LdcPixel_t TextBackgndColour;
+
+static unsigned long TextX_Pos = 0;
+static unsigned long TextY_Pos = 0;
+
+static unsigned long XL_Win = 0;
+static unsigned long YU_Win = 0;
+static unsigned long XR_Win = C_GLCD_H_SIZE-1;
+static unsigned long YD_Win = C_GLCD_V_SIZE-1;
+
+static unsigned long TabSize = TEXT_DEF_TAB_SIZE;
+
+static unsigned long WindY_Size, WindX_Size;
+static unsigned long CurrY_Size, CurrX_Size;
+static unsigned long *pWind;
+static unsigned long *pPix;
+
+/*************************************************************************
+ * Function Name: GLCD_Cursor_Cnfg
+ * Parameters:
+ *
+ * Return: none
+ *
+ * Description: Configure the cursor
+ *
+ *************************************************************************/
+void GLCD_Cursor_Cfg(int Cfg)
+{
+ LPC_LCD->CRSR_CFG = Cfg;
+}
+/*************************************************************************
+ * Function Name: GLCD_Cursor_En
+ * Parameters: cursor - Cursor Number
+ *
+ * Return: none
+ *
+ * Description: Enable Cursor
+ *
+ *************************************************************************/
+void GLCD_Cursor_En(int cursor)
+{
+ LPC_LCD->CRSR_CTRL |= (cursor<<4);
+ LPC_LCD->CRSR_CTRL |= 1;
+}
+
+/*************************************************************************
+ * Function Name: GLCD_Cursor_Dis
+ * Parameters: None
+ *
+ * Return: none
+ *
+ * Description: Disable Cursor
+ *
+ *************************************************************************/
+void GLCD_Cursor_Dis(int cursor)
+{
+ LPC_LCD->CRSR_CTRL &= (1<<0);
+}
+
+/*************************************************************************
+ * Function Name: GLCD_Move_Cursor
+ * Parameters: x - cursor x position
+ * y - cursor y position
+ *
+ * Return: none
+ *
+ * Description: Moves cursor on position (x,y). Negativ values are posible.
+ *
+ *************************************************************************/
+void GLCD_Move_Cursor(int x, int y)
+{
+ LPC_LCD->CRSR_CLIP = 0;
+ LPC_LCD->CRSR_XY = 0;
+ if(0 <= x)
+ {//no clipping
+ LPC_LCD->CRSR_XY |= (x & 0x3FF);
+ }
+ else
+ {//clip x
+ LPC_LCD->CRSR_CLIP |= -x;
+ }
+
+ if(0 <= y)
+ {//no clipping
+
+ LPC_LCD->CRSR_XY |= (y << 16);
+ }
+ else
+ {//clip y
+ LPC_LCD->CRSR_CLIP |= (-y << 8);
+ }
+}
+
+/*************************************************************************
+ * Function Name: GLCD_Copy_Cursor
+ * Parameters: pCursor - pointer to cursor conts image
+ * cursor - cursor Number (0,1,2 or 3)
+ * for 64x64(size 256) pix cursor always use 0
+ * size - cursor size in words
+ * Return: none
+ *
+ * Description: Copy Cursor from const image to LCD RAM image
+ *
+ *************************************************************************/
+void GLCD_Copy_Cursor (const unsigned long *pCursor, int cursor, int size)
+{
+ unsigned long i ;
+ unsigned long * pDst = (unsigned long *)LCD_CURSOR_BASE_ADDR;
+
+ pDst += cursor*64;
+
+ for(i = 0; i < size ; i++)
+// *pDst++ = *pCursor++;
+ {
+ *pDst = *pCursor;
+ pDst++;
+ pCursor++;
+ }
+}
+/*************************************************************************
+ * Function Name: GLCD_Init
+ * Parameters: const unsigned long *pPain, const unsigned long * pPallete
+ *
+ * Return: none
+ *
+ * Description: GLCD controller init
+ *
+ *************************************************************************/
+void GLCD_Init (void* VRAMBase)
+{
+ // unsigned long i;
+ // Assign pins
+ LPC_IOCON->P2_9 = 0x06; // VD3, R0
+ LPC_IOCON->P2_6 = 0x07; // VD4, R1
+ LPC_IOCON->P2_7 = 0x07; // VD5, R2
+ LPC_IOCON->P4_28 = 0x05; // VD6, R3
+ LPC_IOCON->P4_29 = 0x05; // VD7, R4
+
+ LPC_IOCON->P1_20 = 0x07; // VD10, G0
+ LPC_IOCON->P1_21 = 0x07; // VD11, G1
+ LPC_IOCON->P1_22 = 0x07; // VD12, G2
+ LPC_IOCON->P1_23 = 0x07; // VD13, G3
+ LPC_IOCON->P1_24 = 0x07; // VD14, G4
+ LPC_IOCON->P1_25 = 0x07; // VD15, G5
+
+ LPC_IOCON->P2_13 = 0x07; // VD19, B0
+ LPC_IOCON->P1_26 = 0x07; // VD20, B1
+ LPC_IOCON->P1_27 = 0x07; // VD21, B2
+ LPC_IOCON->P1_28 = 0x07; // VD22, B3
+ LPC_IOCON->P1_29 = 0x07; // VD23, B4
+
+ LPC_IOCON->P2_2 = 0x07; // DCLK
+ LPC_IOCON->P2_0 = 0x07; // DSIP(power)
+ LPC_IOCON->P2_5 = 0x07; // HSYNC
+ LPC_IOCON->P2_3 = 0x07; // VSYNC
+ LPC_IOCON->P2_4 = 0x07; // DataEn
+
+// LPC_IOCON->P5_4 = 0x00; // Backlight
+
+ // >>> debug >>>
+
+ // <<< debug <<<
+
+ /*Back light enable*/
+// LPC_GPIO5->DIR = (1<<4);
+// LPC_GPIO5->SET= (5<<4);
+
+ //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;
+ // RGB888
+ LPC_LCD->CTRL &= ~(0x07 <<1);
+ LPC_LCD->CTRL |= (6<<1);
+
+ // 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
+// g_pSC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)C_GLCD_PIX_CLK);
+ LPC_SC->LCD_CFG = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / ((unsigned long)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 = (unsigned long)VRAMBase & ~7UL ;
+ LPC_LCD->LPBASE = (unsigned long)VRAMBase & ~7UL ;
+}
+
+/*************************************************************************
+ * Function Name: GLCD_SetPallet
+ * Parameters: const unsigned long * pPallete
+ *
+ * Return: none
+ *
+ * Description: GLCD init colour pallete
+ *
+ *************************************************************************/
+void GLCD_SetPallet (const unsigned long * pPallete)
+{
+ unsigned long i;
+ unsigned long * pDst = (unsigned long *)LPC_LCD->PAL;
+ // //assert(pPallete);
+ for (i = 0; i < 128; i++)
+ {
+ *pDst++ = *pPallete++;
+ }
+}
+
+/*************************************************************************
+ * Function Name: GLCD_Ctrl
+ * Parameters: Bool bEna
+ *
+ * Return: none
+ *
+ * Description: GLCD enable disabe sequence
+ *
+ *************************************************************************/
+void GLCD_Ctrl (Bool bEna)
+{
+ volatile unsigned long i;
+ if (bEna)
+ {
+// LCD_CTRL_bit.LcdEn = 1;
+ LPC_LCD->CTRL |= (1<<0);
+ for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
+// LCD_CTRL_bit.LcdPwr= 1; // enable power
+ LPC_LCD->CTRL |= (1<<11);
+ }
+ else
+ {
+// LCD_CTRL_bit.LcdPwr= 0; // disable power
+ LPC_LCD->CTRL &= ~(1<<11);
+ for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
+// LCD_CTRL_bit.LcdEn = 0;
+ LPC_LCD->CTRL &= ~(1<<0);
+ }
+}
+
+/*************************************************************************
+ * Function Name: GLCD_SetFont
+ * Parameters: pFontType_t pFont, LdcPixel_t Color
+ * LdcPixel_t BackgndColor
+ *
+ * Return: none
+ *
+ * Description: Set current font, font color and background color
+ *
+ *************************************************************************/
+void GLCD_SetFont(pFontType_t pFont, LdcPixel_t Color, LdcPixel_t BackgndColor)
+{
+ pCurrFont = pFont;
+ TextColour = Color;
+ TextBackgndColour = BackgndColor;
+}
+
+/*************************************************************************
+ * Function Name: GLCD_SetWindow
+ * Parameters: unsigned long X_Left, unsigned long Y_Up,
+ * unsigned long X_Right, unsigned long Y_Down
+ *
+ * Return: none
+ *
+ * Description: Set draw window XY coordinate in pixels
+ *
+ *************************************************************************/
+void GLCD_SetWindow(unsigned long X_Left, unsigned long Y_Up,
+ unsigned long X_Right, unsigned long Y_Down)
+{
+ // //assert(X_Right < C_GLCD_H_SIZE);
+ // //assert(Y_Down < C_GLCD_V_SIZE);
+ // //assert(X_Left < X_Right);
+ //assert(Y_Up < Y_Down);
+ XL_Win = X_Left;
+ YU_Win = Y_Up;
+ XR_Win = X_Right;
+ YD_Win = Y_Down;
+}
+
+/*************************************************************************
+ * Function Name: GLCD_TextSetPos
+ * Parameters: unsigned long X_UpLeft, unsigned long Y_UpLeft,
+ * unsigned long X_DownLeft, unsigned long Y_DownLeft
+ *
+ * Return: none
+ *
+ * Description: Set text X,Y coordinate in characters
+ *
+ *************************************************************************/
+void GLCD_TextSetPos(unsigned long X, unsigned long Y)
+{
+ TextX_Pos = X;
+ TextY_Pos = Y;
+}
+
+/*************************************************************************
+ * Function Name: GLCD_TextSetTabSize
+ * Parameters: unsigned long Size
+ *
+ * Return: none
+ *
+ * Description: Set text tab size in characters
+ *
+ *************************************************************************/
+void GLCD_TextSetTabSize(unsigned long Size)
+{
+ TabSize = Size;
+}
+
+/*************************************************************************
+ * Function Name: LCD_SET_WINDOW
+ * Parameters: int c
+ *
+ * Return: none
+ *
+ * Description: Put char function
+ *
+ *************************************************************************/
+static
+void LCD_SET_WINDOW (unsigned long X_Left, unsigned long X_Right,
+ unsigned long Y_Up, unsigned long Y_Down)
+{
+ pPix = pWind = ((unsigned long *)LCD_VRAM_BASE_ADDR) + X_Left + (Y_Up*C_GLCD_H_SIZE);
+ WindX_Size = X_Right - X_Left;
+ WindY_Size = Y_Down - Y_Up;
+ CurrX_Size = CurrY_Size = 0;
+}
+
+/*************************************************************************
+ * Function Name: LCD_SET_WINDOW
+ * Parameters: int c
+ *
+ * Return: none
+ *
+ * Description: Put char function
+ *
+ *************************************************************************/
+static
+void LCD_WRITE_PIXEL (unsigned long Pixel)
+{
+ *pPix++ = Pixel;
+ if (++CurrX_Size > WindX_Size)
+ {
+ CurrX_Size = 0;
+ if(++CurrY_Size > WindY_Size)
+ {
+ CurrY_Size = 0;
+ }
+ pPix = pWind + CurrY_Size * C_GLCD_H_SIZE;
+ }
+}
+
+/*************************************************************************
+ * Function Name: GLCD_TextCalcWindow
+ * Parameters: unsigned long * pXL, unsigned long * pXR,
+ * unsigned long * pYU, unsigned long * pYD,
+ * unsigned long * pH_Size, unsigned long * pV_Size
+ *
+ * Return: Bool
+ * FALSE - out of window coordinate aren't valid
+ * TRUE - the returned coordinate are valid
+ *
+ * Description: Calculate character window
+ *
+ *************************************************************************/
+static
+Bool GLCD_TextCalcWindow (unsigned long * pXL, unsigned long * pXR,
+ unsigned long * pYU, unsigned long * pYD,
+ unsigned long * pH_Size, unsigned long * pV_Size)
+{
+ *pH_Size = pCurrFont->H_Size;
+ *pV_Size = pCurrFont->V_Size;
+ *pXL = XL_Win + (TextX_Pos*pCurrFont->H_Size);
+ if(*pXL > XR_Win)
+ {
+ return(FALSE);
+ }
+ *pYU = YU_Win + (TextY_Pos*pCurrFont->V_Size);
+ if(*pYU > YD_Win)
+ {
+ return(FALSE);
+ }
+
+ *pXR = XL_Win + ((TextX_Pos+1)*pCurrFont->H_Size) - 1;
+ if(*pXR > XR_Win)
+ {
+ *pH_Size -= *pXR - XR_Win;
+ *pXR = XR_Win;
+ }
+
+ *pYD = YU_Win + ((TextY_Pos+1)*pCurrFont->V_Size) - 1;
+ if(*pYD > YD_Win)
+ {
+ *pV_Size -= *pYD - YD_Win;
+ *pYD = YD_Win;
+ }
+
+ return(TRUE);
+}
+
+/*************************************************************************
+ * Function Name: putchar
+ * Parameters: int c
+ *
+ * Return: none
+ *
+ * Description: Put char function
+ *
+ *************************************************************************/
+int _putchar (int c)
+{
+uint8_t *pSrc;
+unsigned long H_Line;
+unsigned long xl,xr,yu,yd,Temp,V_Size, H_Size, SrcInc = 1;
+unsigned long WhiteSpaceNumb;
+unsigned long i, j, k;
+ if(pCurrFont == NULL)
+ {
+ return(EOF);
+ }
+ H_Line = (pCurrFont->H_Size / 8) + ((pCurrFont->H_Size % 8)?1:0);
+ switch(c)
+ {
+ case '\n': // go to begin of next line (NewLine)
+ ++TextY_Pos;
+ break;
+ case '\r': // go to begin of this line (Carriage Return)
+ // clear from current position to end of line
+ while(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
+ {
+ LCD_SET_WINDOW(xl,xr,yu,yd);
+ for(i = 0; i < V_Size; ++i)
+ {
+ for(j = 0; j < H_Size; ++j)
+ {
+ LCD_WRITE_PIXEL(TextBackgndColour);
+ }
+ }
+ ++TextX_Pos;
+ }
+ TextX_Pos = 0;
+ break;
+ case '\b': // go back one position (BackSpace)
+ if(TextX_Pos)
+ {
+ --TextX_Pos;
+ // del current position
+ if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
+ {
+ LCD_SET_WINDOW(xl,xr,yu,yd);
+ for(i = 0; i < V_Size; ++i)
+ {
+ for(j = 0; j < H_Size; ++j)
+ {
+ LCD_WRITE_PIXEL(TextBackgndColour);
+ }
+ }
+ }
+ }
+ break;
+ case '\t': // go to next Horizontal Tab stop
+ WhiteSpaceNumb = TabSize - (TextX_Pos%TabSize);
+ for(k = 0; k < WhiteSpaceNumb; ++k)
+ {
+ LCD_SET_WINDOW(xl,xr,yu,yd);
+ if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
+ {
+ for(i = 0; i < V_Size; ++i)
+ {
+ for(j = 0; j < H_Size; ++j)
+ {
+ LCD_WRITE_PIXEL(TextBackgndColour);
+ }
+ }
+ ++TextX_Pos;
+ }
+ else
+ {
+ break;
+ }
+ }
+ break;
+ case '\f': // go to top of page (Form Feed)
+ // clear entire window
+ H_Size = XR_Win - XL_Win;
+ V_Size = YD_Win - YU_Win;
+ // set character window X left, Y right
+ LCD_SET_WINDOW(XL_Win,XR_Win,YU_Win,YD_Win);
+ // Fill window with background font color
+ for(i = 0; i <= V_Size; ++i)
+ {
+ for(j = 0; j <= H_Size; ++j)
+ {
+ LCD_WRITE_PIXEL(TextBackgndColour);
+ }
+ }
+
+ TextX_Pos = TextY_Pos = 0;
+ break;
+ case '\a': // signal an alert (BELl)
+ TEXT_BEL1_FUNC();
+ break;
+ default:
+ // Calculate the current character base address from stream
+ // and the character position
+ if((c < pCurrFont->CharacterOffset) &&
+ (c >= pCurrFont->CharactersNuber))
+ {
+ c = 0;
+ }
+ else
+ {
+ c -= pCurrFont->CharacterOffset;
+ }
+ pSrc = pCurrFont->pFontStream + (H_Line * pCurrFont->V_Size * c);
+ // Calculate character window and fit it in the text window
+ if(GLCD_TextCalcWindow(&xl,&xr,&yu,&yd,&H_Size,&V_Size))
+ {
+ // set character window X left, Y right
+ LCD_SET_WINDOW(xl,xr,yu,yd);
+ // Send char data
+ for(i = 0; i < V_Size; ++i)
+ {
+ SrcInc = H_Line;
+ for(j = 0; j < H_Size; ++j)
+ {
+ Temp = (*pSrc & (1UL << (j&0x7)))?TextColour:TextBackgndColour;
+ LCD_WRITE_PIXEL(Temp);
+ if((j&0x7) == 7)
+ {
+ ++pSrc;
+ --SrcInc;
+ }
+ }
+ // next line of character
+ pSrc += SrcInc;
+ }
+ }
+ ++TextX_Pos;
+ }
+ return(c);
+}
+
+/*************************************************************************
+ * Function Name: GLCD_LoadPic
+ * Parameters: unsigned long X_Left, unsigned long Y_Up, Bmp_t * pBmp
+ *
+ * Return: none
+ *
+ * Description: Load picture in VRAM memory area
+ *
+ *************************************************************************/
+void GLCD_LoadPic (unsigned long X_Left, unsigned long Y_Up, Bmp_t * pBmp, unsigned long Mask)
+{
+unsigned long i, j;
+unsigned long * pData = ((unsigned long *) LCD_VRAM_BASE_ADDR) + X_Left + (Y_Up * C_GLCD_H_SIZE);
+unsigned long * pSrc = pBmp->pPicStream;
+unsigned long X_LeftHold;
+ for(i = 0; i < pBmp->V_Size; i++)
+ {
+ if(Y_Up++ >= C_GLCD_V_SIZE)
+ {
+ break;
+ }
+ for(j = 0; j < pBmp->H_Size; j++)
+ {
+ if(X_LeftHold++ >= C_GLCD_H_SIZE)
+ {
+ pSrc += pBmp->H_Size - j;
+ break;
+ }
+ *(pData+j) = *pSrc++ ^ Mask;
+ }
+ X_LeftHold = X_Left;
+ pData += C_GLCD_H_SIZE;
+ }
+}
+
+
diff --git a/bsp/lpc178x/drivers/drv_glcd.h b/bsp/lpc178x/drivers/drv_glcd.h
new file mode 100644
index 0000000000..5f11b822fc
--- /dev/null
+++ b/bsp/lpc178x/drivers/drv_glcd.h
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+* Used with ICCARM and AARM.
+ *
+ * (c) Copyright IAR Systems 2008
+ *
+ * File name : drv_glcd.h
+ * Description : Graphical LCD driver include file
+ *
+ * History :
+ * 1. Date : 6, March 2008
+ * Author : Stanimir Bonev
+ * Description : Create
+ *
+ *
+ * $Revision: 24636 $
+ *
+ * @Modify: NXP MCU Application Team - NguyenCao
+ * @Date: 04. March. 2011
+ **************************************************************************/
+#include "lpc_types.h"
+
+#ifndef __GLCD_DRV_H
+#define __GLCD_DRV_H
+
+typedef unsigned long U32;
+typedef unsigned char U8;
+typedef unsigned long Boolean;
+/**
+ * @brief A struct for Bitmap on LCD screen
+ */
+typedef struct _Bmp_t
+{
+ U32 H_Size;
+ U32 V_Size;
+ U32 BitsPP;
+ U32 BytesPP;
+ U32 *pPalette;
+ U32 *pPicStream;
+ U8 *pPicDesc;
+} Bmp_t, *pBmp_t;
+
+/**
+ * @brief A struct for Font Type on LCD screen
+ */
+
+typedef struct _FontType_t
+{
+ U32 H_Size;
+ U32 V_Size;
+ U32 CharacterOffset;
+ U32 CharactersNuber;
+ U8 *pFontStream;
+ U8 *pFontDesc;
+} FontType_t, *pFontType_t;
+
+typedef U32 LdcPixel_t, *pLdcPixel_t;
+
+#define C_GLCD_REFRESH_FREQ (60HZ)
+#define C_GLCD_H_SIZE 480
+#define C_GLCD_H_PULSE 2 //
+#define C_GLCD_H_FRONT_PORCH 5 //
+#define C_GLCD_H_BACK_PORCH 40 //
+#define C_GLCD_V_SIZE 272
+#define C_GLCD_V_PULSE 2
+#define C_GLCD_V_FRONT_PORCH 8
+#define C_GLCD_V_BACK_PORCH 8
+
+#define C_GLCD_PWR_ENA_DIS_DLY 10000
+#define C_GLCD_ENA_DIS_DLY 10000
+
+//Cursor 64x64 pixels
+#define CURSOR_H_SIZE 64
+#define CURSOR_V_SIZE 64
+//
+#define CIRCLE_R 18
+
+
+#define CRSR_PIX_32 0
+#define CRSR_PIX_64 1
+#define CRSR_ASYNC 0
+#define CRSR_FRAME_SYNC 2
+
+#define TEXT_DEF_TAB_SIZE 5
+
+#define TEXT_BEL1_FUNC()
+
+void GLCD_Init (void* VRAMBase);
+void GLCD_SetPallet (const U32 * pPallete);
+void GLCD_Ctrl (Bool bEna);
+void GLCD_Cursor_Cfg(int Cfg);
+void GLCD_Cursor_En(int cursor);
+void GLCD_Cursor_Dis(int cursor);
+void GLCD_Move_Cursor(int x, int y);
+void GLCD_Copy_Cursor (const U32 *pCursor, int cursor, int size);
+void GLCD_SetFont(pFontType_t pFont, LdcPixel_t Color, LdcPixel_t BackgndColor);
+void GLCD_SetWindow(U32 X_Left, U32 Y_Up,
+ U32 X_Right, U32 Y_Down);
+void GLCD_TextSetPos(U32 X, U32 Y);
+void GLCD_TextSetTabSize(U32 Size);
+static void LCD_SET_WINDOW (U32 X_Left, U32 X_Right,
+ U32 Y_Up, U32 Y_Down);
+static void LCD_WRITE_PIXEL (U32 Pixel);
+static Bool GLCD_TextCalcWindow (U32 * pXL, U32 * pXR,
+ U32 * pYU, U32 * pYD,
+ U32 * pH_Size, U32 * pV_Size);
+void GLCD_LoadPic (U32 X_Left, U32 Y_Up, Bmp_t * pBmp, U32 Mask);
+int _putchar (int c);
+
+
+#endif // __GLCD_DRV_H
diff --git a/bsp/lpc178x/drivers/emac.c b/bsp/lpc178x/drivers/emac.c
index 9c78088ee2..bc0b8ba459 100644
--- a/bsp/lpc178x/drivers/emac.c
+++ b/bsp/lpc178x/drivers/emac.c
@@ -171,7 +171,7 @@ REF_CLK P1_15
static rt_err_t lpc17xx_emac_init(rt_device_t dev)
{
/* Initialize the EMAC ethernet controller. */
- rt_uint32_t regv, tout, id1, id2;
+ rt_uint32_t regv, tout;
/* Power Up the EMAC controller. */
LPC_SC->PCONP |= (1UL<<30);
diff --git a/bsp/lpc178x/drivers/lpc17xx_lcd.c b/bsp/lpc178x/drivers/lpc17xx_lcd.c
index 3eb9d14971..671e55ed17 100644
--- a/bsp/lpc178x/drivers/lpc17xx_lcd.c
+++ b/bsp/lpc178x/drivers/lpc17xx_lcd.c
@@ -3,11 +3,89 @@
#include "LPC177x_8x.h"
#include "lpc177x_8x_pinsel.h"
-/* LCD BL P5_4 */
-void rt_hw_lcd_init(void)
+#include "drv_glcd.h"
+
+#define RT_HW_LCD_WIDTH 480
+#define RT_HW_LCD_HEIGHT 272
+
+static struct rt_device_graphic_info _lcd_info;
+static struct rt_device lcd;
+
+/* RT-Thread Device Interface */
+static rt_err_t rt_lcd_init (rt_device_t dev)
{
PINSEL_ConfigPin(5, 4, 0);
LPC_GPIO5->DIR |= 1<<4;
LPC_GPIO5->CLR = 1<<4;
LPC_GPIO5->SET = 1<<4;
+
+ /*Disable LCD controller*/
+ GLCD_Ctrl (FALSE);
+ /*Init LCD and copy picture in video RAM*/
+ GLCD_Init (_lcd_info.framebuffer);
+ /*Enable LCD*/
+ GLCD_Ctrl (TRUE);
+
+ return RT_EOK;
+}
+
+static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
+{
+ switch (cmd)
+ {
+ case RTGRAPHIC_CTRL_RECT_UPDATE:
+ break;
+ case RTGRAPHIC_CTRL_POWERON:
+ break;
+ case RTGRAPHIC_CTRL_POWEROFF:
+ break;
+ case RTGRAPHIC_CTRL_GET_INFO:
+ rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
+ break;
+ case RTGRAPHIC_CTRL_SET_MODE:
+ break;
+ }
+
+ return RT_EOK;
+}
+
+
+/* LCD BL P5_4 */
+void rt_hw_lcd_init(void)
+{
+ rt_uint16_t * _rt_framebuffer = RT_NULL;
+
+ // _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8);
+ // if (_rt_framebuffer == RT_NULL) return; /* no memory yet */
+
+ _rt_framebuffer = (rt_uint16_t *)0xA0000000;
+
+ _lcd_info.bits_per_pixel = 16;
+ _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
+ _lcd_info.framebuffer = (void*)_rt_framebuffer;
+ _lcd_info.width = RT_HW_LCD_WIDTH;
+ _lcd_info.height = RT_HW_LCD_HEIGHT;
+
+ /* init device structure */
+ lcd.type = RT_Device_Class_Graphic;
+ lcd.init = rt_lcd_init;
+ lcd.open = RT_NULL;
+ lcd.close = RT_NULL;
+ lcd.control = rt_lcd_control;
+ lcd.user_data = (void*)&_lcd_info;
+
+ /* register lcd device to RT-Thread */
+ rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
+}
+
+void lcd_fill(uint8_t * start, uint8_t * end, uint8_t pixel)
+{
+ while(start<end)
+ {
+ *start++ = pixel;
+ }
}
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+FINSH_FUNCTION_EXPORT(lcd_fill, lcd_fill );
+#endif
diff --git a/bsp/lpc178x/drivers/sdram.c b/bsp/lpc178x/drivers/sdram.c
new file mode 100644
index 0000000000..a35b85ef74
--- /dev/null
+++ b/bsp/lpc178x/drivers/sdram.c
@@ -0,0 +1,278 @@
+#include <rtthread.h>
+
+#include <system_LPC177x_8x.h>
+#include "LPC177x_8x.h"
+#include "sdram.h"
+
+//LPC_EMC_TypeDef * const g_pEMC = ((LPC_EMC_TypeDef*) LPC_EMC_BASE);
+//LPC_IOCON_TypeDef * const LPC_IOCON = ((LPC_IOCON_TypeDef*) LPC_IOCON_BASE);
+#define SDRAM_BASE 0xA0000000 /* CS0 */
+#define EMC_NS2CLK(ns, nsPerClk) ((ns + nsPerClk - 1) / nsPerClk)
+
+static void delayMs(int a,int b)
+{
+ volatile unsigned int i;
+ for(i=0;i<10000;i++);
+}
+
+/*****************************************************************************
+** Function name: delayMs
+**
+** Descriptions: Start the timer delay in milo seconds
+** until elapsed
+**
+** parameters: timer number, Delay value in milo second
+**
+** Returned value: None
+**
+*****************************************************************************/
+//void delayMs(uint8_t timer_num, uint32_t delayInMs)
+//{
+// if ( timer_num == 0 )
+// {
+// LPC_TIM0->TCR = 0x02; /* reset timer */
+// LPC_TIM0->PR = 0x00; /* set prescaler to zero */
+// LPC_TIM0->MR0 = delayInMs * (PeripheralClock / 1000 - 1);
+// LPC_TIM0->IR = 0xff; /* reset all interrrupts */
+// LPC_TIM0->MCR = 0x04; /* stop timer on match */
+// LPC_TIM0->TCR = 0x01; /* start timer */
+//
+// /* wait until delay time has elapsed */
+// while (LPC_TIM0->TCR & 0x01);
+// }
+// else if ( timer_num == 1 )
+// {
+// LPC_TIM1->TCR = 0x02; /* reset timer */
+// LPC_TIM1->PR = 0x00; /* set prescaler to zero */
+// LPC_TIM1->MR0 = delayInMs * (PeripheralClock / 1000 - 1);
+// LPC_TIM1->IR = 0xff; /* reset all interrrupts */
+// LPC_TIM1->MCR = 0x04; /* stop timer on match */
+// LPC_TIM1->TCR = 0x01; /* start timer */
+//
+// /* wait until delay time has elapsed */
+// while (LPC_TIM1->TCR & 0x01);
+// }
+// else if ( timer_num == 2 )
+// {
+// LPC_TIM2->TCR = 0x02; /* reset timer */
+// LPC_TIM2->PR = 0x00; /* set prescaler to zero */
+// LPC_TIM2->MR0 = delayInMs * (PeripheralClock / 1000 - 1);
+// LPC_TIM2->IR = 0xff; /* reset all interrrupts */
+// LPC_TIM2->MCR = 0x04; /* stop timer on match */
+// LPC_TIM2->TCR = 0x01; /* start timer */
+//
+// /* wait until delay time has elapsed */
+// while (LPC_TIM2->TCR & 0x01);
+// }
+// else if ( timer_num == 3 )
+// {
+// LPC_TIM3->TCR = 0x02; /* reset timer */
+// LPC_TIM3->PR = 0x00; /* set prescaler to zero */
+// LPC_TIM3->MR0 = delayInMs * (PeripheralClock / 1000 - 1);
+// LPC_TIM3->IR = 0xff; /* reset all interrrupts */
+// LPC_TIM3->MCR = 0x04; /* stop timer on match */
+// LPC_TIM3->TCR = 0x01; /* start timer */
+//
+// /* wait until delay time has elapsed */
+// while (LPC_TIM3->TCR & 0x01);
+// }
+// return;
+//}
+
+static void EMC_GPIO_Init (void)
+{
+ LPC_IOCON->P3_0 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D0 @ P3.0 */
+ LPC_IOCON->P3_1 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D1 @ P3.1 */
+ LPC_IOCON->P3_2 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D2 @ P3.2 */
+ LPC_IOCON->P3_3 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D3 @ P3.3 */
+
+ LPC_IOCON->P3_4 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D4 @ P3.4 */
+ LPC_IOCON->P3_5 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D5 @ P3.5 */
+ LPC_IOCON->P3_6 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D6 @ P3.6 */
+ LPC_IOCON->P3_7 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D7 @ P3.7 */
+
+ LPC_IOCON->P3_8 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D8 @ P3.8 */
+ LPC_IOCON->P3_9 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D9 @ P3.9 */
+ LPC_IOCON->P3_10 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D10 @ P3.10 */
+ LPC_IOCON->P3_11 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D11 @ P3.11 */
+
+ LPC_IOCON->P3_12 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D12 @ P3.12 */
+ LPC_IOCON->P3_13 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D13 @ P3.13 */
+ LPC_IOCON->P3_14 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D14 @ P3.14 */
+ LPC_IOCON->P3_15 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D15 @ P3.15 */
+
+ LPC_IOCON->P3_16 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D16 @ P3.16 */
+ LPC_IOCON->P3_17 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D17 @ P3.17 */
+ LPC_IOCON->P3_18 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D18 @ P3.18 */
+ LPC_IOCON->P3_19 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D19 @ P3.19 */
+
+ LPC_IOCON->P3_20 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D20 @ P3.20 */
+ LPC_IOCON->P3_21 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D21 @ P3.21 */
+ LPC_IOCON->P3_22 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D22 @ P3.22 */
+ LPC_IOCON->P3_23 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D23 @ P3.23 */
+
+ LPC_IOCON->P3_24 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D24 @ P3.24 */
+ LPC_IOCON->P3_25 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D25 @ P3.25 */
+ LPC_IOCON->P3_26 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D26 @ P3.26 */
+ LPC_IOCON->P3_27 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D27 @ P3.27 */
+
+ LPC_IOCON->P3_28 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D28 @ P3.28 */
+ LPC_IOCON->P3_29 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D29 @ P3.29 */
+ LPC_IOCON->P3_30 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D30 @ P3.30 */
+ LPC_IOCON->P3_31 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* D31 @ P3.31 */
+
+ LPC_IOCON->P4_0 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A0 @ P4.0 */
+ LPC_IOCON->P4_1 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A1 @ P4.1 */
+ LPC_IOCON->P4_2 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A2 @ P4.2 */
+ LPC_IOCON->P4_3 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A3 @ P4.3 */
+
+ LPC_IOCON->P4_4 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A4 @ P4.4 */
+ LPC_IOCON->P4_5 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A5 @ P4.5 */
+ LPC_IOCON->P4_6 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A6 @ P4.6 */
+ LPC_IOCON->P4_7 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A7 @ P4.7 */
+
+ LPC_IOCON->P4_8 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A8 @ P4.8 */
+ LPC_IOCON->P4_9 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A9 @ P4.9 */
+ LPC_IOCON->P4_10 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A10 @ P4.10 */
+ LPC_IOCON->P4_11 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A11 @ P4.11 */
+
+ LPC_IOCON->P4_12 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A12 @ P4.12 */
+ LPC_IOCON->P4_13 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A13 @ P4.13 */
+ LPC_IOCON->P4_14 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A14 @ P4.14 */
+ LPC_IOCON->P4_15 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A15 @ P4.15 */
+
+ LPC_IOCON->P4_16 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A16 @ P4.16 */
+ LPC_IOCON->P4_17 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A17 @ P4.17 */
+ LPC_IOCON->P4_18 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A18 @ P4.18 */
+ LPC_IOCON->P4_19 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A19 @ P4.19 */
+
+ LPC_IOCON->P4_20 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A20 @ P4.20 */
+ LPC_IOCON->P4_21 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A21 @ P4.21 */
+ LPC_IOCON->P4_22 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A22 @ P4.22 */
+ LPC_IOCON->P4_23 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* A23 @ P4.23 */
+
+ LPC_IOCON->P4_25 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* WEN @ P4.25 */
+
+#if 1
+ LPC_IOCON->P4_24 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* OEN @ P4.24 */
+
+ LPC_IOCON->P4_26 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[0] @ P4.26 */
+ LPC_IOCON->P4_27 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[1] @ P4.27 */
+
+ LPC_IOCON->P4_28 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[2] @ P4.28 */
+ LPC_IOCON->P4_29 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* BLSN[3] @ P4.29 */
+ LPC_IOCON->P4_30 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CSN[0] @ P4.30 */
+ LPC_IOCON->P4_31 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CSN[1] @ P4.31 */
+
+ LPC_IOCON->P2_14 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CSN[2] @ P2.14 */
+ LPC_IOCON->P2_15 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CSN[3] @ P2.15 */
+#endif
+
+#if 1
+ LPC_IOCON->P2_16 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CASN @ P2.16 */
+ LPC_IOCON->P2_17 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* RASN @ P2.17 */
+ LPC_IOCON->P2_18 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CLK[0] @ P2.18 */
+ LPC_IOCON->P2_19 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CLK[1] @ P2.19 */
+
+ LPC_IOCON->P2_20 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DYCSN[0] @ P2.20 */
+ LPC_IOCON->P2_21 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DYCSN[1] @ P2.21 */
+ LPC_IOCON->P2_22 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DYCSN[2] @ P2.22 */
+ LPC_IOCON->P2_23 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DYCSN[3] @ P2.23 */
+
+ LPC_IOCON->P2_24 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CKE[0] @ P2.24 */
+
+// LPC_IOCON->P2_25 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CKE[1] @ P2.25 */
+ LPC_IOCON->P2_26 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CKE[2] @ P2.26 */
+ LPC_IOCON->P2_27 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* CKE[3] @ P2.27 */
+
+ LPC_IOCON->P2_28 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DQM[0] @ P2.28 */
+ LPC_IOCON->P2_29 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DQM[1] @ P2.29 */
+ LPC_IOCON->P2_30 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DQM[2] @ P2.30 */
+ LPC_IOCON->P2_31 = (1<<0 | 0<<3 | 0<<5 | 1<<9); /* DQM[3] @ P2.31 */
+#endif
+}
+
+void SDRAM_Init (void)
+{
+ uint32_t i, dwtemp = dwtemp;
+ uint16_t wtemp = wtemp;
+ uint32_t mhz, nsPerClk;
+ /* Enable External Memory Controller power/clock */
+ LPC_SC->PCONP |= 0x00000800;
+ LPC_SC->EMCDLYCTL = 0x00001010;
+ LPC_EMC->Control = 0x00000001;
+ LPC_EMC->Config = 0x00000000;
+
+ EMC_GPIO_Init();
+
+ mhz = SystemCoreClock / 1000000;
+ if (LPC_SC->EMCCLKSEL)
+ mhz >>= 1;
+ nsPerClk = 1000 / mhz;
+ LPC_EMC->DynamicRP = EMC_NS2CLK(20, nsPerClk); /* 20ns, */
+ LPC_EMC->DynamicRAS = /*EMC_NS2CLK(42, nsPerClk);*/ 15; /* 42ns to 100K ns, */
+ LPC_EMC->DynamicSREX = 1 - 1; /* tSRE, 1clk, */
+ LPC_EMC->DynamicAPR = 2 - 1; /* Not found!!! Estimated as 2clk, */
+ LPC_EMC->DynamicDAL = EMC_NS2CLK(20, nsPerClk) + 2; /* tDAL = tRP + tDPL = 20ns + 2clk */
+ LPC_EMC->DynamicWR = 2 - 1; /* 2CLK, */
+ LPC_EMC->DynamicRC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRC=63ns(min)*/
+ LPC_EMC->DynamicRFC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRFC=tRC */
+ LPC_EMC->DynamicXSR = 0x0000000F; /* exit self-refresh to active, ��֪������Ϊ��� */
+ LPC_EMC->DynamicRRD = EMC_NS2CLK(63, nsPerClk); /* 3clk, tRRD=15ns(min) */
+ LPC_EMC->DynamicMRD = 2 - 1; /* 2clk, tMRD=2clk(min) */
+
+// LPC_EMC->DynamicRP = 0x00000002; /* 3clk=24ns, */
+// LPC_EMC->DynamicRAS = 0x00000005; /* 6clk=48ns, */
+// LPC_EMC->DynamicSREX = 0x00000001; /* 2clk, */
+// LPC_EMC->DynamicAPR = 0x00000001; /* 2clk, */
+// LPC_EMC->DynamicDAL = 0x00000005; /* 6clk, */
+// LPC_EMC->DynamicWR = 0x00000001; /* 2CLK, */
+// LPC_EMC->DynamicRC = 0x00000008; /* 9clk, H57V2562GTR-75C tRC=63ns(min)*/
+// LPC_EMC->DynamicRFC = 0x00000008; /* 9clk, H57V2562GTR-75C tRFC=63ns(min) */
+// LPC_EMC->DynamicXSR = 0x00000007; /* 8clk, */
+// LPC_EMC->DynamicRRD = 0x00000002; /* 3clk, tRRD=15ns(min) */
+// LPC_EMC->DynamicMRD = 0x00000001; /* 2clk, tMRD=2clk(min) */
+
+ LPC_EMC->DynamicReadConfig = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */
+ /* H57V2562GTR-75C: tCL=3CLK, tRCD=20ns(min), 3 CLK=24ns */
+ LPC_EMC->DynamicRasCas0 = 0x00000303; /* 3 RAS, 3 CAS latency */
+
+ /* For Manley lpc1778 SDRAM: H57V2562GTR-75C, 256Mb, 16Mx16, 4 banks, row=13, column=9 */
+#ifdef SDRAM_CONFIG_16BIT
+ LPC_EMC->DynamicConfig0 = 0x680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */
+#elif defined SDRAM_CONFIG_32BIT
+ LPC_EMC->DynamicConfig0 = 0x4680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */
+#endif
+ delayMs(0, 100);
+
+ LPC_EMC->DynamicControl = 0x00000183; /* Issue NOP command */
+ delayMs(0, 200); /* wait 200ms */
+
+ LPC_EMC->DynamicControl = 0x00000103; /* Issue PALL command */
+
+ LPC_EMC->DynamicRefresh = 0x00000002; /* ( n * 16 ) -> 32 clock cycles */
+ for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */
+ /* 64ms/8192=7.8125us, nx16x8.33ns<7.8125us, n<58.6*/
+ wtemp = 64000000 / (1 << 13);
+ wtemp -= 16;
+ wtemp >>= 4;
+ wtemp = wtemp * mhz / 1000;
+ LPC_EMC->DynamicRefresh = wtemp;
+
+ LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */
+
+#ifdef SDRAM_CONFIG_16BIT
+
+ wtemp = *((volatile uint16_t *)(SDRAM_BASE | (0x33<<12))); /* 8 burst, 3 CAS latency */
+#elif defined SDRAM_CONFIG_32BIT
+ dwtemp = *((volatile uint32_t *)(SDRAM_BASE | (0x32<<13))); /* 4 burst, 3 CAS latency */
+#endif
+
+ LPC_EMC->DynamicControl = 0x00000000; /* Issue NORMAL command */
+
+ LPC_EMC->DynamicConfig0 |= 0x80000; /* enable buffer */
+ delayMs(0, 1);
+
+}
+
+
diff --git a/bsp/lpc178x/drivers/sdram.h b/bsp/lpc178x/drivers/sdram.h
new file mode 100644
index 0000000000..d89e515ebb
--- /dev/null
+++ b/bsp/lpc178x/drivers/sdram.h
@@ -0,0 +1,8 @@
+#ifndef SDRAM_H_INCLUDED
+#define SDRAM_H_INCLUDED
+
+#define SDRAM_CONFIG_32BIT
+
+void SDRAM_Init (void);
+
+#endif // SDRAM_H_INCLUDED
diff --git a/bsp/lpc178x/drivers/uart.c b/bsp/lpc178x/drivers/uart.c
index 608bbaec61..725b7d4028 100644
--- a/bsp/lpc178x/drivers/uart.c
+++ b/bsp/lpc178x/drivers/uart.c
@@ -158,7 +158,6 @@ static rt_err_t rt_uart_init (rt_device_t dev)
// Enable UART Transmit
UART_TxCmd( uart->UART, ENABLE);
-// UART_IntConfig( uart->UART, UART_INTCFG_RLS, ENABLE);
UART_IntConfig( uart->UART, UART_INTCFG_RBR, ENABLE);
}
#endif
@@ -184,7 +183,6 @@ static rt_err_t rt_uart_init (rt_device_t dev)
// Enable UART Transmit
UART_TxCmd( uart->UART, ENABLE);
-// UART_IntConfig( uart->UART, UART_INTCFG_RLS, ENABLE);
UART_IntConfig( uart->UART, UART_INTCFG_RBR, ENABLE);
}
#endif