提交 2fd51d55 编写于 作者: qiuyiuestc's avatar qiuyiuestc

code clean up

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@906 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 d54f2bbf
......@@ -18,8 +18,8 @@
*/
/*@{*/
#include <board.h>
#include <rtthread.h>
#include "dm9000.h"
#include "touch.h"
#include "led.h"
......@@ -37,6 +37,7 @@
#endif
#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
extern void rt_hw_lcd_init(void);
extern void rt_hw_key_init(void);
#endif
......@@ -66,7 +67,7 @@ void rt_init_thread_entry(void* parameter)
#ifdef RT_USING_RTGUI
{
rtgui_touch_hw_init();
rtgui_system_server_init();
rtgui_startup();
}
......@@ -89,21 +90,6 @@ void rt_init_thread_entry(void* parameter)
rt_kprintf("TCP/IP initialized!\n");
}
#endif
/* NFSv3 Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
{
extern void nfs_init(void);
nfs_init();
if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
{
rt_kprintf("NFSv3 File System initialized!\n");
}
else
rt_kprintf("NFSv3 File System initialzation failed!\n");
}
#endif
}
void rt_led_thread_entry(void* parameter)
......@@ -155,4 +141,23 @@ int rt_application_init()
return 0;
}
/* NFSv3 Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
#include <dfs_nfs.h>
void nfs_start(void)
{
nfs_init();
if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0)
{
rt_kprintf("NFSv3 File System initialized!\n");
}
else
rt_kprintf("NFSv3 File System initialzation failed!\n");
}
#include "finsh.h"
FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem);
#endif
/*@}*/
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <stdio.h>
#include <stdlib.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#ifdef RT_USING_LWIP
#include <lwip/err.h>
#include <lwip/dns.h>
#include <lwip/netif.h>
#endif
static struct rtgui_view* device_view = RT_NULL;
int get_thread_cnt()
{
int cnt = 0;
struct rt_list_node *list, *node;
extern struct rt_object_information rt_object_container[];
list = &rt_object_container[RT_Object_Class_Thread].object_list;
for (node = list->next; node != list; node = node->next)
{
cnt ++;
}
return cnt;
}
/*
* Device Information View
* Thread:
* IP Address:
* Gateway:
* DNS:
*/
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
switch (event->type)
{
case RTGUI_EVENT_PAINT:
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
char* line;
rt_uint32_t total, used, max_used;
line = rtgui_malloc(256);
if (line == RT_NULL) return RT_FALSE;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
rtgui_free(line);
return RT_FALSE;
}
rtgui_widget_get_rect(widget, &rect);
/* fill background */
rtgui_dc_fill_rect(dc, &rect);
rect.y2 = rect.y1 + 18;
{
rt_uint16_t rect_width;
rtgui_color_t saved;
rtgui_rect_t mem_rect = rect;
rtgui_rect_inflate(&mem_rect, -2);
rtgui_dc_draw_rect(dc, &mem_rect);
rtgui_rect_inflate(&mem_rect, -1);
rect_width = rtgui_rect_width(mem_rect);
saved = RTGUI_WIDGET_BACKGROUND(widget);
RTGUI_WIDGET_BACKGROUND(widget) = light_grey;
mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total);
rtgui_dc_fill_rect(dc, &mem_rect);
RTGUI_WIDGET_BACKGROUND(widget) = blue;
mem_rect.x2 = mem_rect.x1 + (used * rect_width / total);
rtgui_dc_fill_rect(dc, &mem_rect);
/* restore color */
RTGUI_WIDGET_BACKGROUND(widget) = saved;
}
rect.y1 += 18; rect.y2 += 18;
sprintf(line, "线程数: %d", get_thread_cnt());
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#ifdef RT_USING_LWIP
{
struct ip_addr ip_addr;
struct _ip_addr
{
rt_uint8_t addr0, addr1, addr2, addr3;
} *addr;
addr = (struct _ip_addr*)&netif_default->ip_addr.addr;
sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
addr = (struct _ip_addr*)&netif_default->gw.addr;
sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
addr = (struct _ip_addr*)&netif_default->netmask.addr;
sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#if LWIP_DNS
ip_addr = dns_getserver(0);
addr = (struct _ip_addr*)&ip_addr;
sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3);
rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16;
#endif
}
#endif
rtgui_dc_end_drawing(dc);
rtgui_free(line);
return RT_FALSE;
}
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd;
ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN)
{
rtgui_workbench_t* workbench;
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent);
rtgui_workbench_remove_view(workbench, device_view);
rtgui_view_destroy(device_view);
device_view = RT_NULL;
}
}
return RT_FALSE;
}
/* use parent event handler */
return rtgui_view_event_handler(widget, event);
}
rtgui_view_t *device_view_create(rtgui_workbench_t* workbench)
{
if (device_view != RT_NULL)
{
rtgui_view_show(device_view, RT_FALSE);
}
else
{
/* create a view */
device_view = rtgui_view_create("Device Info");
/* set view event handler */
rtgui_widget_set_event_handler(RTGUI_WIDGET(device_view), view_event_handler);
/* this view can be focused */
RTGUI_WIDGET(device_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* add view to workbench */
rtgui_workbench_add_view(workbench, device_view);
}
return device_view;
}
......@@ -11,7 +11,7 @@
* nLAN_CS connects to nGCS4
*/
// #define DM9000_DEBUG 1
/* #define DM9000_DEBUG 1 */
#if DM9000_DEBUG
#define DM9000_TRACE rt_kprintf
#else
......@@ -163,7 +163,7 @@ void rt_dm9000_isr(int irqno)
last_io = DM9000_IO;
/* Disable all interrupts */
dm9000_io_write(DM9000_IMR, IMR_PAR);
// dm9000_io_write(DM9000_IMR, IMR_PAR);
/* Got DM9000 interrupt status */
int_status = dm9000_io_read(DM9000_ISR); /* Got ISR */
......@@ -186,7 +186,9 @@ void rt_dm9000_isr(int irqno)
if (int_status & ISR_PRS)
{
/* disable receive interrupt */
dm9000_io_write(DM9000_IMR, IMR_PAR);
dm9000_device.imr_all = IMR_PAR | IMR_PTM;
dm9000_io_write(DM9000_IMR, dm9000_device.imr_all);
/* a frame has been received */
eth_device_ready(&(dm9000_device.parent));
......@@ -220,7 +222,7 @@ void rt_dm9000_isr(int irqno)
}
/* Re-enable interrupt mask */
dm9000_io_write(DM9000_IMR, dm9000_device.imr_all);
// dm9000_io_write(DM9000_IMR, dm9000_device.imr_all);
DM9000_IO = last_io;
}
......@@ -290,9 +292,9 @@ static rt_err_t rt_dm9000_init(rt_device_t dev)
while (!(phy_read(1) & 0x20))
{
/* autonegation complete bit */
rt_thread_delay(10);
rt_thread_delay( 10 );
i++;
if (i == 10000)
if (i > 20)
{
rt_kprintf("could not establish link\n");
return 0;
......@@ -462,6 +464,8 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
{
struct pbuf* p;
rt_uint32_t rxbyte;
rt_uint16_t rx_status, rx_len;
rt_uint16_t* data;
/* init p pointer */
p = RT_NULL;
......@@ -469,14 +473,12 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
/* lock DM9000 device */
rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
__error_retry:
/* Check packet ready or not */
dm9000_io_read(DM9000_MRCMDX); /* Dummy read */
rxbyte = DM9000_inb(DM9000_DATA_BASE); /* Got most updated data */
if (rxbyte)
{
rt_uint16_t rx_status, rx_len;
rt_uint16_t* data;
if (rxbyte > 1)
{
DM9000_TRACE("dm9000 rx: rx error, stop device\n");
......@@ -512,13 +514,12 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
len -= 2;
}
}
DM9000_TRACE("\n");
}
else
{
rt_uint16_t dummy;
DM9000_TRACE("dm9000 rx: no pbuf\n");
rt_kprintf("dm9000 rx: no pbuf\n");
/* no pbuf, discard data from DM9000 */
data = &dummy;
......@@ -532,7 +533,7 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
if ((rx_status & 0xbf00) || (rx_len < 0x40)
|| (rx_len > DM9000_PKT_MAX))
{
rt_kprintf("rx error: status %04x\n", rx_status);
rt_kprintf("rx error: status %04x, rx_len: %d\n", rx_status, rx_len);
if (rx_status & 0x100)
{
......@@ -556,12 +557,17 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
}
/* it issues an error, release pbuf */
pbuf_free(p);
if (p != RT_NULL) pbuf_free(p);
p = RT_NULL;
goto __error_retry;
}
}
else
{
/* clear packet received latch status */
dm9000_io_write(DM9000_ISR, ISR_PTS);
/* restore receive interrupt */
dm9000_device.imr_all = IMR_PAR | IMR_PTM | IMR_PRM;
dm9000_io_write(DM9000_IMR, dm9000_device.imr_all);
......
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include "network.xpm"
static rtgui_image_t *rtt_image = RT_NULL;
static rtgui_image_t *network_image = RT_NULL;
static rtgui_image_t *usb_image = RT_NULL;
static rtgui_image_t *power_image = RT_NULL;
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1);
/* draw RT-Thread logo */
rtt_image = rtgui_image_create_from_file("hdc",
"/resource/RTT.hdc", RT_FALSE);
if (rtt_image != RT_NULL)
{
rtgui_image_blit(rtt_image, dc, &rect);
rtgui_image_destroy(rtt_image);
rtt_image = RT_NULL;
}
if (network_image != RT_NULL)
{
rect.x1 = rect.x2 - (network_image->w + 2);
rtgui_image_blit(network_image, dc, &rect);
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
return rtgui_view_event_handler(widget, event);
}
static void info_entry(void* parameter)
{
rt_mq_t mq;
struct rtgui_view* view;
struct rtgui_workbench* workbench;
mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq);
network_image = rtgui_image_create_from_mem("xpm",
(const rt_uint8_t*)network_xpm, sizeof(network_xpm), RT_TRUE);
workbench = rtgui_workbench_create("info", "workbench");
if (workbench == RT_NULL) return;
view = rtgui_view_create("view");
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
rtgui_workbench_add_view(workbench, view);
rtgui_view_show(view, RT_FALSE);
rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void info_init()
{
rt_thread_t tid;
tid = rt_thread_create("info",
info_entry, RT_NULL,
2048, 25, 10);
if (tid != RT_NULL) rt_thread_startup(tid);
}
/* XPM */
static char * network_xpm[] = {
"24 24 145 2",
" c None",
". c #6C6E6A",
"+ c #676965",
"@ c #6B6D6A",
"# c #C6C8C4",
"$ c #F0F1F0",
"% c #F1F1F0",
"& c #C8CAC6",
"* c #646662",
"= c #446795",
"- c #27508B",
"; c #2A538D",
"> c #2E558F",
", c #315890",
"' c #355B92",
") c #385E94",
"! c #3C6196",
"~ c #5C7BA2",
"{ c #F2F3F2",
"] c #626460",
"^ c #F2F2F2",
"/ c #3E6297",
"( c #86ACD5",
"_ c #88AED6",
": c #8BB0D7",
"< c #8DB1D7",
"[ c #8CB1D7",
"} c #8CB0D6",
"| c #8DAED6",
"1 c #5B7AA7",
"2 c #F4F4F4",
"3 c #61635F",
"4 c #30578F",
"5 c #88ADD6",
"6 c #8EB1D7",
"7 c #92B3D8",
"8 c #96B6D8",
"9 c #92B2D6",
"0 c #8CADD3",
"a c #84A7CF",
"b c #5F615D",
"c c #204A87",
"d c #6694C7",
"e c #6391C5",
"f c #618FC3",
"g c #5E8CC1",
"h c #5B8ABF",
"i c #5887BD",
"j c #5684BB",
"k c #5D5F5B",
"l c #5D8CC0",
"m c #5A89BE",
"n c #5886BD",
"o c #5584BB",
"p c #5281B9",
"q c #4F7FB7",
"r c #4D7CB5",
"s c #5C5E5A",
"t c #5482BA",
"u c #5180B8",
"v c #4F7EB6",
"w c #4C7BB4",
"x c #4979B2",
"y c #4676B1",
"z c #4373AF",
"A c #5A5C58",
"B c #406492",
"C c #31527F",
"D c #656D70",
"E c #5E605B",
"F c #C3C4C1",
"G c #80827F",
"H c #C8CAC7",
"I c #545651",
"J c #5E605C",
"K c #6A6E68",
"L c #72756F",
"M c #7B7E79",
"N c #848781",
"O c #8D908A",
"P c #969993",
"Q c #9FA29C",
"R c #416593",
"S c #244E89",
"T c #29518C",
"U c #2D558E",
"V c #325991",
"W c #375C93",
"X c #3B6096",
"Y c #5D7BA3",
"Z c #555753",
"` c #D0D2CE",
" . c #BBBEB7",
".. c #BABDB6",
"+. c #F2F2F1",
"@. c #345A92",
"#. c #81A8D3",
"$. c #83ABD4",
"%. c #8AAFD6",
"&. c #8FB3D8",
"*. c #92B4DA",
"=. c #5978A6",
"-. c #D2D4D1",
";. c #2C548E",
">. c #85ACD5",
",. c #92B5DA",
"'. c #98B9DB",
"). c #95B6DA",
"!. c #90B2D7",
"~. c #88ACD3",
"{. c #464644",
"]. c #719ECE",
"^. c #6E9BCC",
"/. c #6A98C9",
"(. c #6794C7",
"_. c #608EC2",
":. c #5C8BC0",
"<. c #757773",
"[. c #DADAD9",
"}. c #6391C4",
"|. c #5F8DC2",
"1. c #5C8ABF",
"2. c #5181B8",
"3. c #7F817C",
"4. c #ECECEA",
"5. c #5B89BF",
"6. c #5483BA",
"7. c #4D7DB6",
"8. c #4A7AB3",
"9. c #4776B1",
"0. c #80827D",
"a. c #EEEEEC",
"b. c #3F6392",
"c. c #82847F",
"d. c #848680",
"e. c #7F817D",
"f. c #7D7F7B",
"g. c #666863",
"h. c #A8ACA5",
"i. c #B1B3AC",
"j. c #E1E1DE",
"k. c #EDEDEB",
"l. c #E0E0DE",
"m. c #565854",
"n. c #767874",
" ",
" . + + + + + + + + + . ",
" @ # $ % % % % % % % $ & @ ",
" * $ = - ; > , ' ) ! ~ { * ",
" ] ^ / ( _ : < [ } | 1 2 ] ",
" 3 % 4 5 6 7 8 9 0 a ) % 3 ",
" b % c d e f g h i j c % b ",
" k % c l m n o p q r c % k ",
" s % c t u v w x y z c % s ",
" A $ B c c c c c c C D + + + + + + + + + . ",
" E F $ % % % % % % G # $ % % % % % % % $ H @ ",
" I J K L M N O P Q * $ R c S T U V W X Y { * ",
" Z ` .............] +.@.#.$.( %.[ &.*.=.2 ] ",
" Z -.+.+.+.+.+.+.+.3 % ;.>.: ,.'.).!.~.W % 3 ",
" {.Z Z Z Z Z Z Z Z b % c ].^./.(.e _.:.c % b ",
" <.[.<. k % c d }.|.1.i o 2.c % k ",
" 3.4.3. s % c 5.i 6.u 7.8.9.c % s ",
" 0.a.0. A $ B c c c c c c c b.$ A ",
" c...c. E F $ % % % % % % % $ F E ",
" 0.a.0.d.0.e.f.g.J K L M N O P Q h.i.J I ",
" 0.j.a...a.k.l.m.` ............... .` Z ",
" 0.0.c.0.3.n.Z -.+.+.+.+.+.+.+.+.+.-.Z ",
" {.Z Z Z Z Z Z Z Z Z Z Z {. ",
" "};
/* XPM */
static char * network_disconnect_xpm[] = {
"24 24 71 1",
" c None",
". c #191918",
"+ c #181817",
"@ c #808080",
"# c #EDEDED",
"$ c #6B6B6A",
"% c #161615",
"& c #D8D8D8",
"* c #484848",
"= c #A4A4A4",
"- c #E6E6E6",
"; c #F3F3F3",
"> c #F5F5F6",
", c #C0C0C5",
"' c #F3F3F4",
") c #F0F0F0",
"! c #B7B4C3",
"~ c #B7B5C4",
"{ c #F5F5F5",
"] c #A19DB2",
"^ c #EEEEEE",
"/ c #B6B4C3",
"( c #B7B5C3",
"_ c #B3B1C1",
": c #B5B3C1",
"< c #EAEAEB",
"[ c #EFEFEF",
"} c #A19EB2",
"| c #A09CB1",
"1 c #928FA2",
"2 c #676571",
"3 c #D3D3D3",
"4 c #2A2A2A",
"5 c #090909",
"6 c #8B8B8B",
"7 c #0F0F0E",
"8 c #2A2A29",
"9 c #70706F",
"0 c #898988",
"a c #A8A8A8",
"b c #0E0E0D",
"c c #D1D1D1",
"d c #ECECEC",
"e c #EBEBEB",
"f c #D9D9D9",
"g c #C1C1C1",
"h c #B7B7B7",
"i c #BCBCBC",
"j c #141413",
"k c #7F7F7E",
"l c #B6B6B5",
"m c #C8C8C7",
"n c #C0C0C0",
"o c #949494",
"p c #E5E5E5",
"q c #5D5D5C",
"r c #242423",
"s c #9A9A99",
"t c #C8C8C8",
"u c #C5C5C5",
"v c #E8E8E8",
"w c #BABABA",
"x c #DEDEDE",
"y c #D5D5D5",
"z c #C2C2C2",
"A c #B3B3B3",
"B c #909090",
"C c #B6B6B6",
"D c #C4C4C4",
"E c #1F1F1D",
"F c #000000",
" ",
" .........+ ",
" +@#########$% ",
" .#&*******=-. ",
" .;*>,,>,,'*). ",
" .)*!~~~>{]*). ",
" .^*/(_:<<]*[. ",
" .^*}}|}<<]*^. ",
" .#*]]]]]12.........+ ",
" .;3*****4@#########$% ",
" 56######.#&*******=-. ",
" 7890aaaa.;*>,,>,,'*). ",
" b;)cdeee.)*!~~~>{]*). ",
" bfghiiii.^*/(_:<<]*[. ",
" j........^*}}|}<<]*^. ",
" klk .#*]]]]]]]*#. ",
" kmk .;3*******n#. ",
" k3k 56#########o. ",
" kpk 7890aaaa09q.r ",
" kpskkkkb;)cdeeetuuv. ",
" kwxyzABbfghiiiiCcyD. ",
" kkkkkkE...........F ",
" ",
" "};
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#define POINT_LENGTH 320
static rt_uint8_t points[POINT_LENGTH];
static rt_uint8_t old_point, fudu = 1;
static rt_uint16_t current_point = 0;
static rtgui_view_t *osc_view = RT_NULL;
static rtgui_timer_t *osc_timer;
#include <math.h>
void osc_timeout(struct rtgui_timer* timer, void* parameter)
{
struct rtgui_dc* dc;
rtgui_color_t saved;
const double PI=3.141592653589793238462643383279;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(osc_view));
if (dc == RT_NULL) return ;
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view));
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view)) =
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(osc_view));
if (current_point != 0)
rtgui_dc_draw_line(dc, current_point - 1, old_point, current_point, points[current_point]);
else
rtgui_dc_draw_point(dc, current_point, points[current_point]);
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view)) = saved;
old_point = points[current_point];
points[current_point] = 100 * sin((current_point * 4 * fudu) * PI / POINT_LENGTH) + 100;
if (current_point != 0)
rtgui_dc_draw_line(dc, current_point - 1, points[current_point - 1], current_point, points[current_point]);
else
rtgui_dc_draw_point(dc, current_point, points[current_point]);
current_point ++;
if (current_point == POINT_LENGTH)
{
current_point = 0;
fudu ++;
if (fudu == 4) fudu = 1;
}
rtgui_dc_end_drawing(dc);
}
static rt_bool_t osc_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
switch (event->type)
{
case RTGUI_EVENT_PAINT:
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
int index;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
rtgui_dc_fill_rect(dc, &rect);
for (index = 0; index < 320; index ++)
rtgui_dc_draw_point(dc, index, points[index]);
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if ((ekbd->type == RTGUI_KEYDOWN) && (ekbd->key == RTGUIK_RETURN))
{
rtgui_workbench_t* workbench;
/* stop timer */
rtgui_timer_destory(osc_timer);
/* clean points */
rt_memset(points, 0xff, sizeof(points));
current_point = 0;
/* close this view */
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(osc_view)->parent);
rtgui_workbench_remove_view(workbench, osc_view);
rtgui_view_destroy(osc_view);
osc_view = RT_NULL;
fudu = 0;
return RT_FALSE;
}
}
}
return rtgui_view_event_handler(widget, event);
}
rtgui_view_t *osc_view_create(struct rtgui_workbench* workbench)
{
if (osc_view != RT_NULL)
{
rtgui_view_show(osc_view, RT_FALSE);
}
else
{
/* create picture view */
osc_view = rtgui_view_create("Oscilloscope");
rtgui_widget_set_event_handler(RTGUI_WIDGET(osc_view),
osc_view_event_handler);
rtgui_workbench_add_view(workbench, osc_view);
/* this view can be focused */
RTGUI_WIDGET(osc_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
rt_memset(points, 0xff, sizeof(points));
osc_timer = rtgui_timer_create(8,
RT_TIMER_FLAG_PERIODIC,
osc_timeout, RT_NULL);
rtgui_timer_start(osc_timer);
}
return osc_view;
}
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include <dfs_posix.h>
#include <string.h>
enum picture_view_mode
{
VIEW_SINGLE_MODE,
VIEW_DIR_MODE,
VIEW_FN_LIST_MODE
};
static rtgui_view_t* picture_view = RT_NULL;
static enum picture_view_mode view_mode = VIEW_SINGLE_MODE;
/* current picture file name */
static char current_fn[32] = {0};
static const char** picture_fn_list;
static rt_uint8_t picture_fn_list_size, picture_fn_list_current;
static void picture_show_prev()
{
DIR* dir;
struct dirent* entry;
rt_bool_t is_last;
char fn[32];
fn[0] = '\0';
is_last = RT_FALSE;
dir = opendir("/");
if (dir == RT_NULL)
{
rt_kprintf("open directory failed\n");
return;
}
do
{
entry = readdir(dir);
if (entry != RT_NULL)
{
if (strstr(entry->d_name, ".hdc") != RT_NULL ||
strstr(entry->d_name, ".HDC") != RT_NULL)
{
/* it's a HDC image */
if ((strcmp(entry->d_name, current_fn) == 0) &&
is_last != RT_TRUE)
{
if (fn[0] == '\0')
{
/* it should be the last image */
is_last = RT_TRUE;
}
else
{
/* display image */
strcpy(current_fn, fn);
rtgui_widget_update(RTGUI_WIDGET(picture_view));
closedir(dir);
return;
}
}
strcpy(fn, entry->d_name);
}
}
} while(entry != RT_NULL);
/* close directory */
closedir(dir);
if ((is_last == RT_TRUE) && fn[0] != '\0')
{
strcpy(current_fn, fn);
rtgui_widget_update(RTGUI_WIDGET(picture_view));
}
}
static void picture_show_next()
{
DIR* dir;
struct dirent* entry;
rt_bool_t found, has_image;
found = RT_FALSE; has_image = RT_FALSE;
__restart:
dir = opendir("/");
if (dir == RT_NULL)
{
rt_kprintf("open directory failed\n");
return;
}
do
{
entry = readdir(dir);
if (entry != RT_NULL)
{
if (strstr(entry->d_name, ".hdc") != RT_NULL ||
strstr(entry->d_name, ".HDC") != RT_NULL)
{
/* this directory includes image */
has_image = RT_TRUE;
if (found == RT_TRUE || current_fn[0] == '\0')
{
strcpy(current_fn, entry->d_name);
rtgui_widget_update(RTGUI_WIDGET(picture_view));
closedir(dir);
return;
}
/* it's a HDC image */
if (strcmp(entry->d_name, current_fn) == 0)
found = RT_TRUE;
}
}
} while(entry != RT_NULL);
/* close directory */
closedir(dir);
if (has_image != RT_TRUE) return;
current_fn[0] = '\0';
goto __restart;
}
static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
struct rtgui_image* image;
char fn[32];
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
/* open image */
rt_sprintf(fn, "/%s", current_fn);
image = rtgui_image_create_from_file("hdc",
fn, RT_FALSE);
if (image != RT_NULL)
{
/* blit image */
rtgui_image_blit(image, dc, &rect);
/* destroy image */
rtgui_image_destroy(image);
}
else
{
rtgui_dc_fill_rect(dc, &rect);
rtgui_dc_draw_text(dc, "ûļ", &rect);
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
else if (event->type == RTGUI_EVENT_KBD)
{
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
switch (ekbd->key)
{
case RTGUIK_UP:
if (view_mode == VIEW_DIR_MODE) picture_show_next();
else if (view_mode == VIEW_FN_LIST_MODE)
{
picture_fn_list_current ++;
if (picture_fn_list_current == picture_fn_list_size)
{
picture_fn_list_current = 0;
}
strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
rtgui_widget_update(RTGUI_WIDGET(picture_view));
}
break;
case RTGUIK_DOWN:
if (view_mode == VIEW_DIR_MODE) picture_show_prev();
else if (view_mode == VIEW_FN_LIST_MODE)
{
if (picture_fn_list_current == 0)
{
picture_fn_list_current = picture_fn_list_size - 1;
}
else picture_fn_list_current --;
strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
rtgui_widget_update(RTGUI_WIDGET(picture_view));
}
break;
case RTGUIK_RETURN:
{
rtgui_view_t* view;
rtgui_workbench_t* workbench;
/* close this view */
current_fn[0] = '\0';
/* remove view in workbench */
view = RTGUI_VIEW(widget);
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
rtgui_workbench_remove_view(workbench, view);
rtgui_view_destroy(view);
picture_view = RT_NULL;
}
break;
}
}
return RT_FALSE;
}
return rtgui_view_event_handler(widget, event);
}
rtgui_view_t *picture_view_create(struct rtgui_workbench* workbench)
{
if (picture_view != RT_NULL)
{
rtgui_view_show(picture_view, RT_FALSE);
}
else
{
/* create picture view */
picture_view = rtgui_view_create("Picture Presentation");
rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
picture_view_event_handler);
rtgui_workbench_add_view(workbench, picture_view);
/* this view can be focused */
RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
}
return picture_view;
}
rtgui_view_t *picture_view_create_view_file(struct rtgui_workbench* workbench,
const char* filename)
{
if (picture_view != RT_NULL)
{
rtgui_view_show(picture_view, RT_FALSE);
}
else
{
strcpy(current_fn, filename);
/* create picture view */
picture_view = rtgui_view_create("Picture Presentation");
rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
picture_view_event_handler);
rtgui_workbench_add_view(workbench, picture_view);
/* this view can be focused */
RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
view_mode = VIEW_SINGLE_MODE;
}
return picture_view;
}
rtgui_view_t *picture_view_create_view_list(struct rtgui_workbench* workbench,
const char* list[], rt_uint8_t size)
{
if (picture_view != RT_NULL)
{
rtgui_view_show(picture_view, RT_FALSE);
}
else
{
picture_fn_list = list;
picture_fn_list_size = size;
picture_fn_list_current = 0;
strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
/* create picture view */
picture_view = rtgui_view_create("Picture Presentation");
rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
picture_view_event_handler);
rtgui_workbench_add_view(workbench, picture_view);
/* this view can be focused */
RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
view_mode = VIEW_FN_LIST_MODE;
}
return picture_view;
}
#ifndef __PICTURE_H__
#define __PICTURE_H__
rtgui_view_t *picture_view_create(struct rtgui_workbench* workbench);
rtgui_view_t *picture_view_create_view_file(struct rtgui_workbench* workbench, const char* fn);
rtgui_view_t *picture_view_create_view_list(struct rtgui_workbench* workbench, const char* list[], rt_uint8_t size);
#endif
......@@ -169,6 +169,9 @@
/* the number of blocks for pbuf */
#define RT_LWIP_PBUF_NUM 16
/* the number of simultaneously queued TCP */
#define RT_LWIP_TCP_SEG_NUM 40
/* thread priority of tcpip thread */
#define RT_LWIP_TCPTHREAD_PRIORITY 128
......
......@@ -66,7 +66,7 @@ ARCH = 'arm'
CPU = 's3c24x0'
TextBase = '0x30000000'
CROSS_TOOL = 'gcc'
CROSS_TOOL = 'keil'
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
......@@ -121,7 +121,7 @@ elif PLATFORM == 'armcc':
LFLAGS = DEVICE + ' --strict --info sizes --info totals --info unused --info veneers --list rtthread-mini2440.map --ro-base 0x30000000 --entry Entry_Point --first Entry_Point'
CFLAGS += ' -I"' + EXEC_PATH + '/ARM/RV31/INC"'
LFLAGS += ' --libpath "' + EXEC_PATH + '/ARM/RV31/LIB"' + ' --keep __RTMsym_*'
LFLAGS += ' --libpath "' + EXEC_PATH + '/ARM/RV31/LIB"'
EXEC_PATH += '/arm/bin40/'
......
......@@ -19,9 +19,6 @@
#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE)
#include <finsh.h>
extern struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name);
extern void rt_module_run(struct rt_module* module);
void run_module(const char* filename)
{
int fd, length;
......@@ -38,12 +35,13 @@ void run_module(const char* filename)
{
rt_kprintf("check: read file failed\n");
close(fd);
rt_free(buffer);
return;
}
rt_kprintf("read %d bytes from file\n", length);
module_name = strrchr(filename, '/');
module = rt_module_load((void *)buffer, ++module_name);
module = rt_module_load(++module_name, (void *)buffer);
rt_free(buffer);
close(fd);
}
......
......@@ -35,7 +35,6 @@ extern void rt_show_version(void);
extern void rt_system_heap_init(void*, void*);
extern void rt_hw_finsh_init(void);
extern void rt_application_init(void);
extern void rt_calendar(void);
extern struct serial_device uart0;
extern struct rt_device uart0_device;
......@@ -100,9 +99,6 @@ void rtthread_startup(void)
/* show version */
rt_show_version();
/* show calendar */
rt_calendar();
/* init tick */
rt_system_tick_init();
......@@ -139,11 +135,6 @@ void rtthread_startup(void)
rt_device_init_all();
#endif
#ifdef RT_USING_MODULE
/* init module system */
// rt_system_module_init();
#endif
/* init application */
rt_application_init();
......
### uVision2 Project, (C) Keil Software
### Do not modify !
cExt (*.c)
aExt (*.s*; *.src; *.a*)
oExt (*.obj)
lExt (*.lib)
tExt (*.txt; *.h; *.inc)
pExt (*.plm)
CppX (*.cpp)
DaveTm { 0,0,0,0,0,0,0,0 }
Target (RT-Thread Debug), 0x0004 // Tools: 'ARM-ADS'
TARGOPT 1, (RT-Thread Debug)
ADSCLK=12000000
OPTTT 1,1,1,0
OPTHX 1,65535,0,0,0
OPTLX 79,66,8,<.\>
OPTOX 16
OPTLT 1,1,1,0,1,1,0,1,0,0,0,0
OPTXL 1,1,1,1,1,1,1,0,0
OPTFL 1,0,1
OPTAX 255
OPTBL 0,(User's Manual)<DATASHTS\SAMSUNG\S3C2440_UM.PDF>
OPTDL (SARM.DLL)()(DARMSS9.DLL)(-pS3C2440A)(SARM.DLL)()(TARMSS9.DLL)(-pS3C2440A)
OPTDBG 47614,6,()()()()()()()()()(.\Ext_RAM.ini) (Segger\JLTAgdi.dll)()()()
OPTKEY 0,(DLGTARM)((113=-1,-1,-1,-1,0)(100=90,124,666,445,0)(102=-1,-1,-1,-1,0)(103=-1,-1,-1,-1,0)(104=-1,-1,-1,-1,0)(105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)(108=-1,-1,-1,-1,0)(109=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(112=-1,-1,-1,-1,0))
OPTKEY 0,(JLTAgdi)(-O65838 -J1 -Y800 -Z4 -FO7 -FD30000000 -FC8000 -FN1 -FF0S3C2440_NAND_SP -FS030000000 -FL08000000)
OPTKEY 0,(JLTDLG)()
OPTKEY 0,(DLGDARM)((113=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(102=-1,-1,-1,-1,0)(103=-1,-1,-1,-1,0)(104=-1,-1,-1,-1,0)(105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)(108=-1,-1,-1,-1,0)(109=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(112=-1,-1,-1,-1,0))
OPTKEY 0,(ARMDBGFLAGS)(-T5F)
OPTMM 1,2,(0x3020000)
OPTDF 0x86
OPTLE <>
OPTLC <>
EndOpt
#include <rtgui/rtgui.h>
#include <rtgui/image.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/list_view.h>
#include <rtgui/widgets/workbench.h>
#include <rtgui/widgets/filelist_view.h>
#include <string.h>
#include "picture.h"
static rtgui_image_t *background = RT_NULL;
rtgui_image_t *selected_image = RT_NULL;
static struct rtgui_view* function_view;
static struct rtgui_view* home_view;
static struct rtgui_workbench* workbench;
const char *introduction_list[] =
{
"/rtt/01.hdc",
"/rtt/02.hdc",
"/rtt/03.hdc",
"/rtt/04.hdc",
"/rtt/05.hdc",
"/rtt/06.hdc",
"/rtt/07.hdc",
"/rtt/08.hdc",
};
void function_introduction(void* parameter)
{
rtgui_view_t *view;
view = picture_view_create_view_list(workbench, introduction_list,
sizeof(introduction_list)/sizeof(char*));
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
void function_filelist(void* parameter)
{
rtgui_rect_t rect;
rtgui_view_t *view;
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = (rtgui_view_t*)rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
void function_osc(void* parameter)
{
rtgui_view_t *view;
extern rtgui_view_t *osc_view_create(rtgui_workbench_t *workbench);
view = osc_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
void function_device(void* parameter)
{
rtgui_view_t *view;
extern rtgui_view_t *device_view_create(rtgui_workbench_t *workbench);
view = device_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
}
void function_action(void* parameter)
{
rt_kprintf("item action!\n");
return;
}
struct rtgui_list_item function_list[] =
{
{"RT-Thread介绍", RT_NULL, function_introduction, RT_NULL},
{"文件浏览", RT_NULL, function_filelist, RT_NULL},
{"波形演示", RT_NULL, function_osc, RT_NULL},
{"设备信息", RT_NULL, function_device, RT_NULL},
};
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if (event->type == RTGUI_EVENT_PAINT)
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect);
/* draw background */
background = rtgui_image_create_from_file("hdc",
"/resource/bg.hdc", RT_FALSE);
if (background != RT_NULL)
{
rtgui_image_blit(background, dc, &rect);
rtgui_image_destroy(background);
background = RT_NULL;
}
else
{
rtgui_dc_fill_rect(dc, &rect);
}
rtgui_dc_end_drawing(dc);
return RT_FALSE;
}
else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
{
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
if (emouse->button == RTGUI_MOUSE_BUTTON_UP | RTGUI_MOUSE_BUTTON_LEFT)
{
rtgui_view_show(function_view, RT_FALSE);
}
return RT_FALSE;
}
return rtgui_view_event_handler(widget, event);
}
rt_bool_t today_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
{
if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
{
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
//if (emouse->button == RTGUI_MOUSE_BUTTON_UP | RTGUI_MOUSE_BUTTON_LEFT)
if(0)
{
/* active home view */
if (workbench->current_view != home_view)
{
rtgui_view_show(home_view, RT_FALSE);
return RT_FALSE;
}
}
}
return rtgui_workbench_event_handler(widget, event);
}
static void today_entry(void* parameter)
{
rt_mq_t mq;
rtgui_rect_t rect;
mq = rt_mq_create("qToday", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq);
selected_image = rtgui_image_create_from_file("hdc",
"/resource/select.hdc", RT_FALSE);
workbench = rtgui_workbench_create("main", "workbench");
if (workbench == RT_NULL) return;
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), today_workbench_event_handler);
/* add home view */
home_view = rtgui_view_create("Home");
rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);
rtgui_workbench_add_view(workbench, home_view);
/* this view can be focused */
RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* set widget focus */
rtgui_widget_focus(RTGUI_WIDGET(home_view));
rtgui_view_show(home_view, RT_FALSE);
/* add function view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
function_view = (struct rtgui_view*)rtgui_list_view_create(function_list,
sizeof(function_list)/sizeof(struct rtgui_list_item), &rect, RTGUI_LIST_VIEW_LIST);
rtgui_workbench_add_view(workbench, function_view);
rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
}
void today_init()
{
rt_thread_t tid;
tid = rt_thread_create("today",
today_entry, RT_NULL,
2048, 25, 10);
if (tid != RT_NULL) rt_thread_startup(tid);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册