diff --git a/bsp/ls1bdev/SConscript b/bsp/ls1bdev/SConscript index a0c60722c0..dc4ae18a10 100644 --- a/bsp/ls1bdev/SConscript +++ b/bsp/ls1bdev/SConscript @@ -5,6 +5,9 @@ src_bsp = ['application.c', 'startup.c', 'board.c'] src_drv = ['uart.c'] +if GetDepend('RT_USING_RTGUI'): + src_drv += ['display_controller.c'] + src = File(src_bsp + src_drv) CPPPATH = [GetCurrentDir()] group = DefineGroup('Startup', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/ls1bdev/SConstruct b/bsp/ls1bdev/SConstruct index 0980f7a2ab..5a5e89a0eb 100644 --- a/bsp/ls1bdev/SConstruct +++ b/bsp/ls1bdev/SConstruct @@ -21,6 +21,9 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT) +if GetDepend('RT_USING_RTGUI'): + objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0) + # build program env.Program(TARGET, objs) diff --git a/bsp/ls1bdev/application.c b/bsp/ls1bdev/application.c index 0a810452b5..fae195627d 100644 --- a/bsp/ls1bdev/application.c +++ b/bsp/ls1bdev/application.c @@ -16,8 +16,33 @@ #include #include +#ifdef RT_USING_RTGUI +#include +extern void rt_hw_dc_init(void); +#endif + void rt_init_thread_entry(void* parameter) { +#ifdef RT_USING_RTGUI + { + rt_device_t dc; + + /* init Display Controller */ + rt_hw_dc_init(); + + /* re-init device driver */ + rt_device_init_all(); + + /* find Display Controller device */ + dc = rt_device_find("dc"); + + /* set Display Controller device as rtgui graphic driver */ + rtgui_graphic_set_device(dc); + + /* startup rtgui */ + rtgui_startup(); + } +#endif } int rt_application_init() diff --git a/bsp/ls1bdev/display_controller.c b/bsp/ls1bdev/display_controller.c new file mode 100644 index 0000000000..511f2dbe0d --- /dev/null +++ b/bsp/ls1bdev/display_controller.c @@ -0,0 +1,234 @@ +/* + * File : display_controller.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2011-08-09 lgnq first version for LS1B DC + */ + +#include +#include "display_controller.h" + +struct vga_struct vga_mode[] = +{ + {/*"640x480_70.00"*/ 28560, 640, 664, 728, 816, 480, 481, 484, 500, }, + {/*"640x640_60.00"*/ 33100, 640, 672, 736, 832, 640, 641, 644, 663, }, + {/*"640x768_60.00"*/ 39690, 640, 672, 736, 832, 768, 769, 772, 795, }, + {/*"640x800_60.00"*/ 42130, 640, 680, 744, 848, 800, 801, 804, 828, }, + {/*"800x480_70.00"*/ 35840, 800, 832, 912, 1024, 480, 481, 484, 500, }, + {/*"800x600_60.00"*/ 38220, 800, 832, 912, 1024, 600, 601, 604, 622, }, + {/*"800x640_60.00"*/ 40730, 800, 832, 912, 1024, 640, 641, 644, 663, }, + {/*"832x600_60.00"*/ 40010, 832, 864, 952, 1072, 600, 601, 604, 622, }, + {/*"832x608_60.00"*/ 40520, 832, 864, 952, 1072, 608, 609, 612, 630, }, + {/*"1024x480_60.00"*/ 38170, 1024, 1048, 1152, 1280, 480, 481, 484, 497, }, + {/*"1024x600_60.00"*/ 48960, 1024, 1064, 1168, 1312, 600, 601, 604, 622, }, + {/*"1024x640_60.00"*/ 52830, 1024, 1072, 1176, 1328, 640, 641, 644, 663, }, + {/*"1024x768_60.00"*/ 64110, 1024, 1080, 1184, 1344, 768, 769, 772, 795, }, + {/*"1152x764_60.00"*/ 71380, 1152, 1208, 1328, 1504, 764, 765, 768, 791, }, + {/*"1280x800_60.00"*/ 83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, }, + {/*"1280x1024_55.00"*/ 98600, 1280, 1352, 1488, 1696, 1024, 1025, 1028, 1057, }, + {/*"1440x800_60.00"*/ 93800, 1440, 1512, 1664, 1888, 800, 801, 804, 828, }, + {/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, }, +}; + +ALIGN(16) +volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE]; +static struct rt_device_graphic_info _dc_info; + +#define abs(x) ((x<0)?(-x):x) +#define min(a,b) ((atype = RT_Device_Class_Graphic; + dc->init = rt_dc_init; + dc->open = RT_NULL; + dc->close = RT_NULL; + dc->control = rt_dc_control; + dc->user_data = (void*)&_dc_info; + + /* register Display Controller device to RT-Thread */ + rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR); +} diff --git a/bsp/ls1bdev/display_controller.h b/bsp/ls1bdev/display_controller.h new file mode 100644 index 0000000000..85086daf31 --- /dev/null +++ b/bsp/ls1bdev/display_controller.h @@ -0,0 +1,58 @@ +/* + * File : display_controller.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2011, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2011-08-08 lgnq first version for LS1B + */ + +#ifndef __DISPLAY_CONTROLLER_H__ +#define __DISPLAY_CONTROLLER_H__ + +#include +#include "ls1b.h" + +#define DC_BASE 0xBC301240 //Display Controller + +/* Frame Buffer registers */ +#define DC_FB_CONFIG __REG32(DC_BASE + 0x000) +#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020) +#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040) +#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060) +#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120) +#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140) +#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160) +#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180) +#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0) +#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0) +#define DC_HSYNC __REG32(DC_BASE + 0x1E0) +#define DC_VDISPLAY __REG32(DC_BASE + 0x240) +#define DC_VSYNC __REG32(DC_BASE + 0x260) +#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340) + +/* Display Controller driver for 1024x768 16bit */ +#define FB_XSIZE 1024 +#define FB_YSIZE 768 +#define CONFIG_VIDEO_16BPP + +#define APB_CLK 33333333 + +#define K1BASE 0xA0000000 +#define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr))) +#define HW_FB_ADDR KSEG1(_rt_framebuffer) +#define HW_FB_PIXEL(x, y) *(volatile rt_uint16_t*)((rt_uint8_t*)HW_FB_ADDR + (y * FB_XSIZE * 2) + x * 2) + +struct vga_struct +{ + long pclk; + int hr,hss,hse,hfl; + int vr,vss,vse,vfl; +}; + +#endif diff --git a/bsp/ls1bdev/rtconfig.h b/bsp/ls1bdev/rtconfig.h index 2e454662c2..337edd5402 100644 --- a/bsp/ls1bdev/rtconfig.h +++ b/bsp/ls1bdev/rtconfig.h @@ -140,7 +140,7 @@ #define RT_LWIP_ETHTHREAD_STACKSIZE 512 /* SECTION: RT-Thread/GUI */ -/* #define RT_USING_RTGUI */ +#define RT_USING_RTGUI /* name length of RTGUI object */ #define RTGUI_NAME_MAX 12 diff --git a/bsp/ls1bdev/uart.c b/bsp/ls1bdev/uart.c index fa33194bb8..4c8d13d298 100644 --- a/bsp/ls1bdev/uart.c +++ b/bsp/ls1bdev/uart.c @@ -15,7 +15,7 @@ #include #include -#include "ls1b.h" +#include "uart.h" /** * @addtogroup Loongson LS1B @@ -24,30 +24,6 @@ /*@{*/ #if defined(RT_USING_UART) && defined(RT_USING_DEVICE) -/* UART interrupt enable register value */ -#define UARTIER_IME (1 << 3) -#define UARTIER_ILE (1 << 2) -#define UARTIER_ITXE (1 << 1) -#define UARTIER_IRXE (1 << 0) - -/* UART line control register value */ -#define UARTLCR_DLAB (1 << 7) -#define UARTLCR_BCB (1 << 6) -#define UARTLCR_SPB (1 << 5) -#define UARTLCR_EPS (1 << 4) -#define UARTLCR_PE (1 << 3) -#define UARTLCR_SB (1 << 2) - -/* UART line status register value */ -#define UARTLSR_ERROR (1 << 7) -#define UARTLSR_TE (1 << 6) -#define UARTLSR_TFE (1 << 5) -#define UARTLSR_BI (1 << 4) -#define UARTLSR_FE (1 << 3) -#define UARTLSR_PE (1 << 2) -#define UARTLSR_OE (1 << 1) -#define UARTLSR_DR (1 << 0) - struct rt_uart_ls1b { struct rt_device parent; diff --git a/bsp/ls1bdev/uart.h b/bsp/ls1bdev/uart.h index 14844ad835..763ba514bd 100644 --- a/bsp/ls1bdev/uart.h +++ b/bsp/ls1bdev/uart.h @@ -1,5 +1,5 @@ /* - * File : board.c + * File : uart.h * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006-2011, RT-Thread Develop Team * @@ -9,12 +9,89 @@ * * Change Logs: * Date Author Notes - * 2011-08-08 lgnq first version + * 2011-08-08 lgnq first version for LS1B */ - #ifndef __UART_H__ #define __UART_H__ +#include "ls1b.h" + +#define UART0_BASE 0xBFE40000 +#define UART0_1_BASE 0xBFE41000 +#define UART0_2_BASE 0xBFE42000 +#define UART0_3_BASE 0xBFE43000 +#define UART1_BASE 0xBFE44000 +#define UART1_1_BASE 0xBFE45000 +#define UART1_2_BASE 0xBFE46000 +#define UART1_3_BASE 0xBFE47000 +#define UART2_BASE 0xBFE48000 +#define UART3_BASE 0xBFE4C000 +#define UART4_BASE 0xBFE6C000 +#define UART5_BASE 0xBFE7C000 + +/* UART registers */ +#define UART_DAT(base) __REG8(base + 0x00) +#define UART_IER(base) __REG8(base + 0x01) +#define UART_IIR(base) __REG8(base + 0x02) +#define UART_FCR(base) __REG8(base + 0x02) +#define UART_LCR(base) __REG8(base + 0x03) +#define UART_MCR(base) __REG8(base + 0x04) +#define UART_LSR(base) __REG8(base + 0x05) +#define UART_MSR(base) __REG8(base + 0x06) + +#define UART_LSB(base) __REG8(base + 0x00) +#define UART_MSB(base) __REG8(base + 0x01) + +/* UART0 registers */ +#define UART0_DAT __REG8(UART0_BASE + 0x00) +#define UART0_IER __REG8(UART0_BASE + 0x01) +#define UART0_IIR __REG8(UART0_BASE + 0x02) +#define UART0_FCR __REG8(UART0_BASE + 0x02) +#define UART0_LCR __REG8(UART0_BASE + 0x03) +#define UART0_MCR __REG8(UART0_BASE + 0x04) +#define UART0_LSR __REG8(UART0_BASE + 0x05) +#define UART0_MSR __REG8(UART0_BASE + 0x06) + +#define UART0_LSB __REG8(UART0_BASE + 0x00) +#define UART0_MSB __REG8(UART0_BASE + 0x01) + +/* UART1 registers */ +#define UART1_DAT __REG8(UART1_BASE + 0x00) +#define UART1_IER __REG8(UART1_BASE + 0x01) +#define UART1_IIR __REG8(UART1_BASE + 0x02) +#define UART1_FCR __REG8(UART1_BASE + 0x02) +#define UART1_LCR __REG8(UART1_BASE + 0x03) +#define UART1_MCR __REG8(UART1_BASE + 0x04) +#define UART1_LSR __REG8(UART1_BASE + 0x05) +#define UART1_MSR __REG8(UART1_BASE + 0x06) + +#define UART1_LSB __REG8(UART1_BASE + 0x00) +#define UART1_MSB __REG8(UART1_BASE + 0x01) + +/* UART interrupt enable register value */ +#define UARTIER_IME (1 << 3) +#define UARTIER_ILE (1 << 2) +#define UARTIER_ITXE (1 << 1) +#define UARTIER_IRXE (1 << 0) + +/* UART line control register value */ +#define UARTLCR_DLAB (1 << 7) +#define UARTLCR_BCB (1 << 6) +#define UARTLCR_SPB (1 << 5) +#define UARTLCR_EPS (1 << 4) +#define UARTLCR_PE (1 << 3) +#define UARTLCR_SB (1 << 2) + +/* UART line status register value */ +#define UARTLSR_ERROR (1 << 7) +#define UARTLSR_TE (1 << 6) +#define UARTLSR_TFE (1 << 5) +#define UARTLSR_BI (1 << 4) +#define UARTLSR_FE (1 << 3) +#define UARTLSR_PE (1 << 2) +#define UARTLSR_OE (1 << 1) +#define UARTLSR_DR (1 << 0) + void rt_hw_uart_init(void); #endif diff --git a/libcpu/mips/loongson_1b/ls1b.h b/libcpu/mips/loongson_1b/ls1b.h index fcea5a7de0..34393a3448 100644 --- a/libcpu/mips/loongson_1b/ls1b.h +++ b/libcpu/mips/loongson_1b/ls1b.h @@ -11,6 +11,7 @@ * Date Author Notes * 2011-08-08 lgnq first version */ + #ifndef __LS1B_H__ #define __LS1B_H__ @@ -113,16 +114,6 @@ struct ls1b_cop_regs #define GMAC0_DMA_BASE 0xBFE11000 #define GMAC1_BASE 0xBFE20000 #define GMAC1_DMA_BASE 0xBFE21000 -#define UART0_BASE 0xBFE40000 -#define UART0_1_BASE 0xBFE41000 -#define UART0_2_BASE 0xBFE42000 -#define UART0_3_BASE 0xBFE43000 -#define UART1_BASE 0xBFE44000 -#define UART1_1_BASE 0xBFE45000 -#define UART1_2_BASE 0xBFE46000 -#define UART1_3_BASE 0xBFE47000 -#define UART2_BASE 0xBFE48000 -#define UART3_BASE 0xBFE4C000 #define I2C0_BASE 0xBFE58000 #define PWM0_BASE 0xBFE5C000 #define PWM1_BASE 0xBFE5C010 @@ -131,77 +122,18 @@ struct ls1b_cop_regs #define WDT_BASE 0xBFE5C060 #define RTC_BASE 0xBFE64000 #define I2C1_BASE 0xBFE68000 -#define UART4_BASE 0xBFE6C000 #define I2C2_BASE 0xBFE70000 #define AC97_BASE 0xBFE74000 #define NAND_BASE 0xBFE78000 -#define UART5_BASE 0xBFE7C000 #define SPI_BASE 0xBFE80000 #define CAN1_BASE 0xBF004300 #define CAN0_BASE 0xBF004400 -#define DC_BASE 0xBC301240 //Display Control - -/* UART registers */ -#define UART_DAT(base) __REG8(base + 0x00) -#define UART_IER(base) __REG8(base + 0x01) -#define UART_IIR(base) __REG8(base + 0x02) -#define UART_FCR(base) __REG8(base + 0x02) -#define UART_LCR(base) __REG8(base + 0x03) -#define UART_MCR(base) __REG8(base + 0x04) -#define UART_LSR(base) __REG8(base + 0x05) -#define UART_MSR(base) __REG8(base + 0x06) - -#define UART_LSB(base) __REG8(base + 0x00) -#define UART_MSB(base) __REG8(base + 0x01) - -/* UART0 registers */ -#define UART0_DAT __REG8(UART0_BASE + 0x00) -#define UART0_IER __REG8(UART0_BASE + 0x01) -#define UART0_IIR __REG8(UART0_BASE + 0x02) -#define UART0_FCR __REG8(UART0_BASE + 0x02) -#define UART0_LCR __REG8(UART0_BASE + 0x03) -#define UART0_MCR __REG8(UART0_BASE + 0x04) -#define UART0_LSR __REG8(UART0_BASE + 0x05) -#define UART0_MSR __REG8(UART0_BASE + 0x06) - -#define UART0_LSB __REG8(UART0_BASE + 0x00) -#define UART0_MSB __REG8(UART0_BASE + 0x01) - -/* UART1 registers */ -#define UART1_DAT __REG8(UART1_BASE + 0x00) -#define UART1_IER __REG8(UART1_BASE + 0x01) -#define UART1_IIR __REG8(UART1_BASE + 0x02) -#define UART1_FCR __REG8(UART1_BASE + 0x02) -#define UART1_LCR __REG8(UART1_BASE + 0x03) -#define UART1_MCR __REG8(UART1_BASE + 0x04) -#define UART1_LSR __REG8(UART1_BASE + 0x05) -#define UART1_MSR __REG8(UART1_BASE + 0x06) - -#define UART1_LSB __REG8(UART1_BASE + 0x00) -#define UART1_MSB __REG8(UART1_BASE + 0x01) - /* Watch Dog registers */ #define WDT_EN __REG32(WDT_BASE + 0x00) #define WDT_SET __REG32(WDT_BASE + 0x04) #define WDT_TIMER __REG32(WDT_BASE + 0x08) -/* Frame Buffer registers */ -#define DC_FB_CONFIG __REG32(DC_BASE + 0x000) -#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020) -#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040) -#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060) -#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120) -#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140) -#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160) -#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180) -#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0) -#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0) -#define DC_HSYNC __REG32(DC_BASE + 0x1E0) -#define DC_VDISPLAY __REG32(DC_BASE + 0x240) -#define DC_VSYNC __REG32(DC_BASE + 0x260) -#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340) - #define PLL_FREQ __REG32(0xbfe78030) #define PLL_DIV_PARAM __REG32(0xbfe78034)