summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqiuyiuestc <[email protected]>2010-10-19 09:20:21 +0000
committerqiuyiuestc <[email protected]>2010-10-19 09:20:21 +0000
commit9536c463864fcee22b74a2d930144864ec0e1358 (patch)
tree38ffd413735afcb2a7d0e0a7d7eec42160ba4bf7
parente98032b2842b9a2c88df31fbdf37798153badd10 (diff)
add virtual key driver for QEUM/mini2440
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1020 bbd45198-f89e-11dd-88c7-29a3b14d5316
-rw-r--r--bsp/mini2440/board.c11
-rw-r--r--bsp/mini2440/key.c206
-rw-r--r--bsp/mini2440/startup.c24
3 files changed, 131 insertions, 110 deletions
diff --git a/bsp/mini2440/board.c b/bsp/mini2440/board.c
index 9cfab4e052..ee7b802806 100644
--- a/bsp/mini2440/board.c
+++ b/bsp/mini2440/board.c
@@ -11,7 +11,7 @@
* Date Author Notes
* 2006-03-24 Bernard first implementation
* 2006-05-05 Bernard add DATA_COUNT definition
- * 2006-10-05 Alsor.Z for s3c2410x porting
+ * 2006-10-05 Alsor.Z for s3c2410x porting
* 2007-11-20 Yi.Qiu add lcd,touch,console
*/
@@ -27,16 +27,12 @@
/*@{*/
extern rt_uint32_t PCLK, FCLK, HCLK, UCLK;
-extern rt_uint8_t asc16_font[];
-extern rt_uint16_t _rt_hw_framebuffer[];
extern void rt_hw_clock_init(void);
extern void rt_hw_lcd_init(void);
extern void rt_hw_mmu_init(void);
extern void rt_hw_touch_init(void);
-
-extern void rt_kbd_init(void);
-extern void rt_console_init(rt_uint8_t*, rt_uint8_t*, rt_uint8_t);
+extern void rt_hw_key_init(void);
extern void rt_hw_get_clock(void);
extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
@@ -152,6 +148,9 @@ void rt_hw_board_init()
/* initialize uart */
rt_hw_uart_init();
+ /* init virtual keypad */
+ rt_hw_key_init();
+
/* initialize mmu */
rt_hw_mmu_init();
diff --git a/bsp/mini2440/key.c b/bsp/mini2440/key.c
index c0c16836f1..5aac56bda3 100644
--- a/bsp/mini2440/key.c
+++ b/bsp/mini2440/key.c
@@ -1,110 +1,146 @@
#include <rtthread.h>
#include <s3c24x0.h>
+#ifdef RT_USING_RTGUI
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
+#endif
-/*
-key_enter GPG0
-key_down GPG3
-key_up GPG5
-key_right GPG6
-key_left GPG7
-key_power GPG11
-*/
-#define key_enter_GETVALUE() (GPGDAT & (1 << 0))
-#define key_down_GETVALUE() (GPGDAT & (1 << 3))
-#define key_up_GETVALUE() (GPGDAT & (1 << 5))
-#define key_right_GETVALUE() (GPGDAT & (1 << 6))
-#define key_left_GETVALUE() (GPGDAT & (1 << 7))
-#define key_power_GETVALUE() (GPGDAT & (1 << 11))
-
-static void key_thread_entry(void *parameter)
+static void key_handle(int key_value)
{
- rt_time_t next_delay;
+#ifdef RT_USING_RTGUI
struct rtgui_event_kbd kbd_event;
-
- /* init gpio configuration */
- GPGCON = GPGCON & (~((3<<22)|(3<<6)|(3<<0)|(3<<10)|(3<<12)|(3<<14))) |
- ((2<<22)|(2<<6)|(2<<0)|(2<<10)|(2<<12)|(2<<14));
-
+
/* init keyboard event */
RTGUI_EVENT_KBD_INIT(&kbd_event);
kbd_event.mod = RTGUI_KMOD_NONE;
kbd_event.unicode = 0;
+ kbd_event.key = RTGUIK_UNKNOWN;
- while (1)
+ if(key_value & 0x80)
+ {
+ kbd_event.type = RTGUI_KEYUP;
+ }
+ else
{
- next_delay = 20;
- kbd_event.key = RTGUIK_UNKNOWN;
-
kbd_event.type = RTGUI_KEYDOWN;
- if ( key_enter_GETVALUE() == 0 )
- {
- rt_thread_delay(next_delay);
- if (key_enter_GETVALUE() == 0)
- {
- /* HOME key */
- rt_kprintf("key_home\n");
- kbd_event.key = RTGUIK_HOME;
- }
- else
- {
- rt_kprintf("key_enter\n");
- kbd_event.key = RTGUIK_RETURN;
- }
- }
+ }
+
+ key_value &= 0x7F;
+ switch(key_value)
+ {
+ case 80:
+ kbd_event.key = RTGUIK_DOWN;
+ break;
+ case 72:
+ kbd_event.key = RTGUIK_UP;
+ break;
+ case 77:
+ kbd_event.key = RTGUIK_RIGHT;
+ break;
+ case 75:
+ kbd_event.key = RTGUIK_LEFT;
+ break;
+ case 31:
+ kbd_event.key = 's';
+ break;
+ case 30:
+ kbd_event.key = 'a';
+ break;
+ case 44:
+ kbd_event.key = 'z';
+ break;
+ case 45:
+ kbd_event.key = 'x';
+ break;
+ case 46:
+ kbd_event.key = 'c';
+ break;
+ case 16:
+ kbd_event.key = 'q';
+ break;
+ case 33:
+ kbd_event.key = 'r';
+ break;
+ case 23:
+ kbd_event.key = 'i';
+ break;
+ case 50:
+ kbd_event.key = 'm';
+ break;
+ case 38:
+ kbd_event.key = 'l';
+ break;
+ case 47:
+ kbd_event.key = 'v';
+ break;
+
+ default:
+ break;
+ }
+
+ if (kbd_event.key != RTGUIK_UNKNOWN)
+ {
+ /* post down event */
+ rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
+ }
+#endif
+}
- if ( key_down_GETVALUE() == 0 )
- {
- rt_kprintf("key_down\n");
- kbd_event.key = RTGUIK_DOWN;
- }
+/**
+ * This function is only for QEMU emulation
+ */
+void rt_virtual_key_isr(int vector)
+{
+ INTSUBMSK |= (BIT_SUB_RXD1);
- if ( key_up_GETVALUE() == 0 )
- {
- rt_kprintf("key_up\n");
- kbd_event.key = RTGUIK_UP;
- }
+ key_handle(URXH1);
+
+ SUBSRCPND |= BIT_SUB_RXD1;
+
+ /*Unmask sub interrupt (RXD0)*/
+ INTSUBMSK &=~(BIT_SUB_RXD1);
+}
- if ( key_right_GETVALUE() == 0 )
- {
- rt_kprintf("key_right\n");
- kbd_event.key = RTGUIK_RIGHT;
- }
+/**
+ * This function is only for QEMU emulation
+ */
+void rt_hw_key_init(void)
+{
+ unsigned long i;
- if ( key_left_GETVALUE() == 0 )
- {
- rt_kprintf("key_left\n");
- kbd_event.key = RTGUIK_LEFT;
- }
+ GPHCON |= 0xa0;
+ /*PULLUP is enable */
+ GPHUP |= 0x0c;
+
+ /* FIFO enable, Tx/Rx FIFO clear */
+ UFCON1 = 0x0;
+ /* disable the flow control */
+ UMCON1= 0x0;
+ /* Normal,No parity,1 stop,8 bit */
+ ULCON1 = 0x3;
+ /*
+ * tx=level,rx=edge,disable timeout int.,enable rx error int.,
+ * normal,interrupt or polling
+ */
+ UCON1 = 0x245;
- if (kbd_event.key != RTGUIK_UNKNOWN)
- {
- /* post down event */
- rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
+ //UBRD0 = div;
+ // UBRD0 = 0x500; /* baudrate = 19200bps */
+ UBRD1 = 0x1a;
- next_delay = 10;
- /* delay to post up event */
- rt_thread_delay(next_delay);
+ UTXH1 = 0x2;
+ URXH1 = 0x1;
- /* post up event */
- kbd_event.type = RTGUI_KEYUP;
- rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
- }
+ /* output PCLK to UART0/1, PWMTIMER */
+ CLKCON |= 0x0D00;
- /* wait next key press */
- rt_thread_delay(next_delay);
- }
-}
+ for (i = 0; i < 100; i++);
-void rt_hw_key_init()
-{
- #if 0
- rt_thread_t key_tid;
- key_tid = rt_thread_create("key",
- key_thread_entry, RT_NULL,
- 512, 30, 5);
- if (key_tid != RT_NULL) rt_thread_startup(key_tid);
- #endif
+ /* install keypad isr */
+ INTSUBMSK &= ~(BIT_SUB_RXD1);
+
+ rt_hw_interrupt_install(INTUART1, rt_virtual_key_isr, RT_NULL);
+ rt_hw_interrupt_umask(INTUART1);
}
+
diff --git a/bsp/mini2440/startup.c b/bsp/mini2440/startup.c
index 29f07a7657..d0bb5e5019 100644
--- a/bsp/mini2440/startup.c
+++ b/bsp/mini2440/startup.c
@@ -58,25 +58,6 @@ extern struct rt_device uart0_device;
extern unsigned char __bss_end;
#endif
-/**
- * Fix me
- */
- #if (defined (__GNUC__))
-void *_sbrk (int incr)
-{
- static char * heap_end;
- char * prev_heap_end;
-
- if (heap_end == 0)
- heap_end = & __bss_end;
-
- prev_heap_end = heap_end;
- heap_end += incr;
-
- return (void *) prev_heap_end;
-}
-#endif
-
#ifdef RT_USING_FINSH
extern void finsh_system_init(void);
#endif
@@ -115,6 +96,11 @@ void rtthread_startup(void)
rt_system_heap_init((void*)&__bss_end, (void*)0x33F00000);
#endif
+#ifdef RT_USING_MODULE
+ /* init module system*/
+ rt_system_module_init();
+#endif
+
/* init scheduler system */
rt_system_scheduler_init();