提交 d3c6a6ab 编写于 作者: B bernard.xiong

add lcd driver; add gui routine

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@105 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 a0e99e8a
......@@ -22,6 +22,8 @@
#include <stm32f10x.h>
#include "board.h"
#include "netbuffer.h"
#include "lcd.h"
#ifdef RT_USING_DFS
/* dfs init */
......@@ -39,6 +41,11 @@
#include <lwip/api.h>
#endif
#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#endif
/*
key_enter PA0
key_down PA1
......@@ -77,41 +84,6 @@ void rt_key_entry(void *parameter)
}
}
extern rt_err_t lcd_hw_init(void);
void rt_lcd_entry(void *parameter)
{
rt_device_t device;
unsigned int i,k;
unsigned short color[]={0xf800,0x07e0,0x001f,0xffe0,0x0000,0xffff,0x07ff,0xf81f};
lcd_hw_init();
device = rt_device_find("lcd");
rt_kprintf("Now test the LCD......\r\n");
while (1)
{
for (k=0;k<8;k++)
{
for (i=0;i<320*240;i++)
{
device->write(device,i*2,&color[k],2);
}
rt_thread_delay(RT_TICK_PER_SECOND);
}
}
}
void lcd_test()
{
rt_thread_t lcd_tid;
lcd_tid = rt_thread_create("lcd",
rt_lcd_entry, RT_NULL,
1024, 30, 5);
if (lcd_tid != RT_NULL) rt_thread_startup(lcd_tid);
}
FINSH_FUNCTION_EXPORT(lcd_test, test lcd)
/* thread phase init */
void rt_init_thread_entry(void *parameter)
{
......@@ -146,12 +118,40 @@ void rt_init_thread_entry(void *parameter)
/* init netbuf worker */
net_buf_init(320 * 1024);
#endif
/* RTGUI Initialization */
#ifdef RT_USING_RTGUI
{
rtgui_rect_t rect;
rtgui_system_server_init();
/* register dock panel */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 240;
rect.y2 = 25;
rtgui_panel_register("info", &rect);
/* register main panel */
rect.x1 = 0;
rect.y1 = 25;
rect.x2 = 240;
rect.y2 = 320;
rtgui_panel_register("main", &rect);
rt_hw_lcd_init();
}
#endif
}
int rt_application_init()
{
rt_thread_t init_thread;
rt_hw_lcd_init();
#if (RT_THREAD_PRIORITY_MAX == 32)
init_thread = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
......
......@@ -178,6 +178,31 @@ void rt_hw_board_init()
}
}
#if STM32_CONSOLE_USART == 1
#define CONSOLE_RX_PIN GPIO_Pin_9
#define CONSOLE_TX_PIN GPIO_Pin_10
#define CONSOLE_GPIO GPIOA
#define CONSOLE_USART USART1
#elif STM32_CONSOLE_USART == 2
#if defined(STM32_LD) || defined(STM32_MD)
#define CONSOLE_RX_PIN GPIO_Pin_6
#define CONSOLE_TX_PIN GPIO_Pin_5
#define CONSOLE_GPIO GPIOD
#elif defined(STM32_HD)
#define CONSOLE_RX_PIN GPIO_Pin_3
#define CONSOLE_TX_PIN GPIO_Pin_2
#define CONSOLE_GPIO GPIOA
#endif
#define CONSOLE_USART USART2
#elif STM32_CONSOLE_USART == 2
#define CONSOLE_RX_PIN GPIO_Pin_11
#define CONSOLE_TX_PIN GPIO_Pin_10
#define CONSOLE_GPIO GPIOB
#define CONSOLE_USART USART3
#endif
/* init console to support rt_kprintf */
static void rt_hw_console_init()
{
......@@ -186,27 +211,29 @@ static void rt_hw_console_init()
| RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOF, ENABLE);
#if STM32_CONSOLE_USART == 0
#else
/* GPIO configuration */
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Pin = CONSOLE_RX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(CONSOLE_GPIO, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Pin = CONSOLE_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(CONSOLE_GPIO, &GPIO_InitStructure);
}
/* USART configuration */
{
USART_InitTypeDef USART_InitStructure;
/* USART1 configured as follow:
/* USART configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
......@@ -225,10 +252,11 @@ static void rt_hw_console_init()
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Init(CONSOLE_USART, &USART_InitStructure);
/* Enable USART1 */
USART_Cmd(USART1, ENABLE);
USART_Cmd(CONSOLE_USART, ENABLE);
}
#endif
}
/* write one character to serial, must not trigger interrupt */
......@@ -240,8 +268,8 @@ static void rt_hw_console_putc(const char c)
*/
if (c=='\n')rt_hw_console_putc('\r');
while (!(USART1->SR & USART_FLAG_TXE));
USART1->DR = (c & 0x1FF);
while (!(CONSOLE_USART->SR & USART_FLAG_TXE));
CONSOLE_USART->DR = (c & 0x1FF);
}
/**
......@@ -251,10 +279,14 @@ static void rt_hw_console_putc(const char c)
*/
void rt_hw_console_output(const char* str)
{
#if STM32_CONSOLE_USART == 0
/* no console */
#else
while (*str)
{
rt_hw_console_putc (*str++);
}
#endif
}
/*@}*/
......@@ -37,6 +37,10 @@
// <i>Default: 64
#define STM32_SRAM_SIZE 64
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
// <o> Console on USART: <0=> no console <1=>USART 1 <2=>USART 2 <3=> USART 3
// <i>Default: 1
#define STM32_CONSOLE_USART 1
void rt_hw_board_led_on(int n);
void rt_hw_board_led_off(int n);
......
......@@ -13,8 +13,8 @@
#define LCD_ADDR (*((volatile unsigned char *) 0x64000000)) // RS = 0
#define LCD_DATA (*((volatile unsigned char *) 0x64000004)) // RS = 1
#define LCD_DATA16(a) LCD_DATA = (unsigned char)(a>>8);LCD_DATA = (unsigned char)a // RS = 1 & WIDHT = 16
#define LCD_DATA16_READ(a) do { a = (LCD_DATA << 8) | (LCD_DATA); } while (0)
#define LCD_WR_CMD(a,b,c) LCD_ADDR = b;LCD_DATA16(c)
#define LCD_WR_REG(a) LCD_ADDR = a
#define LCD_WR_DATA8(a) LCD_DATA = a
......
#include <rtgui/rtgui.h>
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/label.h>
#include <finsh.h>
void msg()
{
struct rtgui_win* msgbox;
struct rtgui_rect rect = {50, 50, 200, 200};
msgbox = rtgui_win_create("Information", &rect, RTGUI_WIN_STYLE_DEFAULT);
if (msgbox != RT_NULL)
{
struct rtgui_box* box = rtgui_box_create(RTGUI_VERTICAL, RT_NULL);
struct rtgui_label* label = rtgui_label_create("Hello World");
rtgui_win_set_box(msgbox, box);
RTGUI_WIDGET(label)->align = RTGUI_ALIGN_CENTER_HORIZONTAL |
RTGUI_ALIGN_CENTER_VERTICAL;
rtgui_box_append(box, RTGUI_WIDGET(label));
rtgui_win_show(msgbox);
}
}
FINSH_FUNCTION_EXPORT(msg, msg on gui)
#include "stm32f10x.h"
#include "rtthread.h"
#include "fmt0371/FMT0371.h"
#include <rtgui/rtgui.h>
#include <rtgui/driver.h>
static rt_err_t lcd_init (rt_device_t dev)
void rt_hw_lcd_update(rtgui_rect_t *rect);
rt_uint8_t * rt_hw_lcd_get_framebuffer(void);
void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2);
struct rtgui_graphic_driver _rtgui_lcd_driver =
{
ftm0371_port_init();
ftm0371_init();
return RT_EOK;
"lcd",
2,
240,
320,
rt_hw_lcd_update,
rt_hw_lcd_get_framebuffer,
rt_hw_lcd_set_pixel,
rt_hw_lcd_get_pixel,
rt_hw_lcd_draw_hline,
rt_hw_lcd_draw_vline
};
void rt_hw_lcd_update(rtgui_rect_t *rect)
{
/* nothing for none-DMA mode driver */
}
static rt_err_t lcd_open(rt_device_t dev, rt_uint16_t oflag)
rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
{
return RT_EOK;
return RT_NULL; /* no framebuffer driver */
}
static rt_err_t lcd_close(rt_device_t dev)
void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
{
return RT_EOK;
unsigned short p;
/* get color pixel */
p = rtgui_color_to_565(*c);
/* set X point */
LCD_ADDR = 0x02;
LCD_DATA = x;
/* set Y point */
LCD_ADDR = 0x03;
LCD_DATA16(y);
/* write pixel */
LCD_ADDR = 0x0E;
LCD_DATA16(p);
}
static rt_err_t lcd_control(rt_device_t dev, rt_uint8_t cmd, void *args)
void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
{
/* rate control */
return RT_EOK;
/* set X point */
LCD_ADDR = 0x02;
LCD_DATA = x;
/* set Y point */
LCD_ADDR = 0x03;
LCD_DATA16( y );
/* read pixel */
LCD_ADDR = 0x0F;
LCD_DATA16_READ(*c);
}
static rt_size_t lcd_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
{
unsigned int i;
unsigned short *p;
unsigned int x,y;
unsigned short p;
size = size / 2;
y = (pos/2) / 240;
x = (pos/2)%240;
/* get color pixel */
p = rtgui_color_to_565p(*c);
LCD_ADDR = 0x02; // X start point
LCD_DATA = x;
/* set X point */
LCD_ADDR = 0x02;
LCD_DATA = x1;
LCD_ADDR = 0x03; // Y start point
/* set Y point */
LCD_ADDR = 0x03;
LCD_DATA16( y );
LCD_ADDR = 0x0E; // start write
p = (unsigned short *) buffer;
if (size > (240-x))
{
for (i=0;i<(240-x);i++)
{
LCD_DATA16(*p++);
}
LCD_ADDR = 0x02; // X start point
LCD_DATA = 0;
LCD_ADDR = 0x03; // Y start point
LCD_DATA16( y+1 );
size -= (x+1);
while (size--)
{
LCD_DATA16(*p++);
}
}
else
{
for (i=0;i<size;i++)
{
LCD_DATA16(*p++);
}
}
return RT_EOK;
/* write pixel */
LCD_ADDR = 0x0E;
while (x1 < x2)
{
LCD_DATA16(p);
x1 ++;
}
}
struct rt_device lcd_device;
rt_err_t lcd_hw_init(void)
void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
{
unsigned short p;
/* get color pixel */
p = rtgui_color_to_565p(*c);
/* set X point */
LCD_ADDR = 0x02;
LCD_DATA = x;
while(y1 < y2)
{
/* set Y point */
LCD_ADDR = 0x03;
LCD_DATA16( y1 );
/* write pixel */
LCD_ADDR = 0x0E;
LCD_DATA16(p);
y1 ++;
}
}
rt_err_t rt_hw_lcd_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
......@@ -89,16 +133,34 @@ rt_err_t lcd_hw_init(void)
ftm0371_port_init();
ftm0371_init();
lcd_device.type = RT_Device_Class_Block;
lcd_device.rx_indicate = RT_NULL;
lcd_device.tx_complete = RT_NULL;
lcd_device.init = lcd_init;
lcd_device.open = lcd_open;
lcd_device.close = lcd_close;
lcd_device.read = RT_NULL;
lcd_device.write = lcd_write;
lcd_device.control = lcd_control;
lcd_device.private = RT_NULL;
return rt_device_register(&lcd_device, "lcd",RT_DEVICE_FLAG_RDWR);
#ifndef DRIVER_TEST
/* add lcd driver into graphic driver */
rtgui_graphic_driver_add(&_rtgui_lcd_driver);
#endif
return RT_EOK;
}
#include <finsh.h>
void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel)
{
rt_hw_lcd_draw_hline(&pixel, x1, x2, y);
}
FINSH_FUNCTION_EXPORT(hline, draw a hline);
void vline(int x, int y1, int y2, rt_uint32_t pixel)
{
rt_hw_lcd_draw_vline(&pixel, x, y1, y2);
}
FINSH_FUNCTION_EXPORT(vline, draw a vline);
void cls()
{
rt_size_t index;
rtgui_color_t white = RTGUI_RGB(0xff, 0xff, 0xff);
for(index = 0; index < 320; index ++)
rt_hw_lcd_draw_hline(&white, 0, 240, index);
}
FINSH_FUNCTION_EXPORT(cls, clear screen);
/*
* File : lcd.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development 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
* 2009-10-16 Bernard first version
*/
#ifndef __LCD_HW_H__
#define __LCD_HW_H__
rt_err_t rt_hw_lcd_init(void);
#endif
此差异已折叠。
......@@ -12,6 +12,7 @@ Group (finsh)
Group (Filesystem)
Group (LwIP)
Group (mp3)
Group (RTGUI)
File 1,5,<.\rtconfig.h><rtconfig.h>
File 1,5,<.\board.h><board.h>
......@@ -35,6 +36,7 @@ File 1,1,<..\..\net\apps\udpecho.c><udpecho.c>
File 1,1,<.\mp3.c><mp3.c>
File 1,1,<.\wav.c><wav.c>
File 1,1,<.\netbuffer.c><netbuffer.c>
File 1,1,<.\gui.c><gui.c>
File 2,1,<..\..\src\clock.c><clock.c>
File 2,1,<..\..\src\idle.c><idle.c>
File 2,1,<..\..\src\ipc.c><ipc.c>
......@@ -162,6 +164,37 @@ File 9,1,<.\mp3\real\subband.c><subband.c>
File 9,1,<.\mp3\real\trigtabs.c><trigtabs.c>
File 9,2,<.\mp3\real\arm\asmpoly_thumb2.s><asmpoly_thumb2.s>
File 9,2,<.\mp3\real\arm\asmmisc.s><asmmisc.s>
File 10,1,<..\..\rtgui\common\rtgui_object.c><rtgui_object.c>
File 10,1,<..\..\rtgui\common\rtgui_system.c><rtgui_system.c>
File 10,1,<..\..\rtgui\common\rtgui_theme.c><rtgui_theme.c>
File 10,1,<..\..\rtgui\common\asc12font.c><asc12font.c>
File 10,1,<..\..\rtgui\common\color.c><color.c>
File 10,1,<..\..\rtgui\common\dc.c><dc.c>
File 10,1,<..\..\rtgui\common\dc_buffer.c><dc_buffer.c>
File 10,1,<..\..\rtgui\common\dc_hw.c><dc_hw.c>
File 10,1,<..\..\rtgui\common\filerw.c><filerw.c>
File 10,1,<..\..\rtgui\common\font.c><font.c>
File 10,1,<..\..\rtgui\common\image.c><image.c>
File 10,1,<..\..\rtgui\common\image_xpm.c><image_xpm.c>
File 10,1,<..\..\rtgui\common\region.c><region.c>
File 10,1,<..\..\rtgui\server\server.c><server.c>
File 10,1,<..\..\rtgui\server\driver.c><driver.c>
File 10,1,<..\..\rtgui\server\panel.c><panel.c>
File 10,1,<..\..\rtgui\widgets\widget.c><widget.c>
File 10,1,<..\..\rtgui\widgets\window.c><window.c>
File 10,1,<..\..\rtgui\widgets\workbench.c><workbench.c>
File 10,1,<..\..\rtgui\widgets\view.c><view.c>
File 10,1,<..\..\rtgui\widgets\box.c><box.c>
File 10,1,<..\..\rtgui\widgets\button.c><button.c>
File 10,1,<..\..\rtgui\widgets\container.c><container.c>
File 10,1,<..\..\rtgui\widgets\iconbox.c><iconbox.c>
File 10,1,<..\..\rtgui\widgets\label.c><label.c>
File 10,1,<..\..\rtgui\widgets\textbox.c><textbox.c>
File 10,1,<..\..\rtgui\widgets\title.c><title.c>
File 10,1,<..\..\rtgui\widgets\toplevel.c><toplevel.c>
File 10,1,<..\..\rtgui\server\mouse.c><mouse.c>
File 10,1,<..\..\rtgui\server\topwin.c><topwin.c>
File 10,1,<..\..\rtgui\common\caret.c><caret.c>
Options 1,0,0 // Target 'RT-Thread STM32 Radio'
......@@ -222,7 +255,7 @@ Options 1,0,0 // Target 'RT-Thread STM32 Radio'
ADSCMISC ()
ADSCDEFN (USE_STDPERIPH_DRIVER, STM32F10X_HD,)
ADSCUDEF ()
ADSCINCD (.;.\Libraries\STM32F10x_StdPeriph_Driver\inc;.\Libraries\CMSIS\Core\CM3;..\..\include;..\..\libcpu\arm\stm32;..\..\finsh;..\..\net\lwip\src;..\..\net\lwip\src\include;..\..\net\lwip\src\arch\include;..\..\net\lwip\src\include\ipv4;..\..\filesystem\dfs;..\..\filesystem\dfs\include;..\..\filesystem\dfs\filesystems\efsl\src\include;..\..\filesystem\dfs\filesystems\efsl\src\base\include;..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\include)
ADSCINCD (.;.\Libraries\STM32F10x_StdPeriph_Driver\inc;.\Libraries\CMSIS\Core\CM3;..\..\include;..\..\libcpu\arm\stm32;..\..\finsh;..\..\net\lwip\src;..\..\net\lwip\src\include;..\..\net\lwip\src\arch\include;..\..\net\lwip\src\include\ipv4;..\..\filesystem\dfs;..\..\filesystem\dfs\include;..\..\filesystem\dfs\filesystems\efsl\src\include;..\..\filesystem\dfs\filesystems\efsl\src\base\include;..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\include;..\..\rtgui\include)
ADSASFLG { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSAMISC ()
ADSADEFN ()
......@@ -276,3 +309,42 @@ Options 1,9,0 // Group 'mp3'
ADSAINCD ()
EndOpt
Options 1,10,0 // Group 'RTGUI'
PropFld { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
ADSASFLG { 170,42,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSAMISC ()
ADSADEFN ()
ADSAUDEF ()
ADSAINCD ()
EndOpt
Options 1,1,23 // File 'gui.c'
PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=2
AlwaysBuild=2
GenAsm=2
AsmAsm=2
PublicsOnly=2
StopCode=11
CustArgs ()
LibMods ()
ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC (--gnu)
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
EndOpt
......@@ -156,5 +156,6 @@
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 4
#define RT_LWIP_ETHTHREAD_STACKSIZE 512
#define RT_USING_RTGUI
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册