2009-11-06 07:59:01 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <stm32f10x.h>
|
|
|
|
|
|
|
|
#include <rtgui/event.h>
|
|
|
|
#include <rtgui/rtgui_server.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
key_enter PA0
|
|
|
|
key_down PA1
|
|
|
|
key_up PA2
|
|
|
|
key_right PC2
|
|
|
|
key_left PC3
|
|
|
|
*/
|
2010-01-19 22:31:11 +08:00
|
|
|
#define key_enter_GETVALUE() GPIO_ReadInputDataBit(GPIOF,GPIO_Pin_11)
|
|
|
|
#define key_down_GETVALUE() GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_15)
|
|
|
|
#define key_up_GETVALUE() GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_11)
|
|
|
|
#define key_right_GETVALUE() GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_14)
|
|
|
|
#define key_left_GETVALUE() GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_13)
|
2009-11-06 07:59:01 +08:00
|
|
|
|
2010-02-02 03:47:12 +08:00
|
|
|
/* from remote.c */
|
|
|
|
extern void rem_start(void);
|
|
|
|
extern void rem_encoder(struct rtgui_event_kbd * p);
|
|
|
|
extern unsigned int rem_mode;
|
|
|
|
/* from remote.c */
|
|
|
|
|
2009-11-06 07:59:01 +08:00
|
|
|
static void key_thread_entry(void *parameter)
|
|
|
|
{
|
|
|
|
rt_time_t next_delay;
|
|
|
|
struct rtgui_event_kbd kbd_event;
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
/* init gpio configuration */
|
2010-01-19 22:31:11 +08:00
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE,ENABLE);
|
2009-11-06 07:59:01 +08:00
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
2010-01-19 22:31:11 +08:00
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
|
|
|
|
GPIO_Init(GPIOG,&GPIO_InitStructure);
|
2009-11-06 07:59:01 +08:00
|
|
|
|
2010-01-19 22:31:11 +08:00
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
|
|
|
GPIO_Init(GPIOF,&GPIO_InitStructure);
|
|
|
|
|
|
|
|
/* PE2 LED */
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
GPIO_Init(GPIOE,&GPIO_InitStructure);
|
|
|
|
GPIO_SetBits(GPIOE,GPIO_Pin_2);
|
2009-11-06 07:59:01 +08:00
|
|
|
|
2010-02-02 03:47:12 +08:00
|
|
|
rem_start();
|
|
|
|
|
2009-11-06 07:59:01 +08:00
|
|
|
/* init keyboard event */
|
|
|
|
RTGUI_EVENT_KBD_INIT(&kbd_event);
|
|
|
|
kbd_event.mod = RTGUI_KMOD_NONE;
|
|
|
|
kbd_event.unicode = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2010-01-31 02:33:27 +08:00
|
|
|
next_delay = 10;
|
|
|
|
kbd_event.key = RTGUIK_UNKNOWN;
|
2009-11-06 07:59:01 +08:00
|
|
|
kbd_event.type = RTGUI_KEYDOWN;
|
2010-02-02 03:47:12 +08:00
|
|
|
|
|
|
|
if( rem_mode== 2 )
|
|
|
|
{
|
|
|
|
rem_encoder(&kbd_event);
|
|
|
|
}
|
|
|
|
|
2009-11-06 07:59:01 +08:00
|
|
|
if ( key_enter_GETVALUE() == 0 )
|
|
|
|
{
|
2010-01-31 02:33:27 +08:00
|
|
|
rt_thread_delay( next_delay*4 );
|
2009-11-06 07:59:01 +08:00
|
|
|
if (key_enter_GETVALUE() == 0)
|
|
|
|
{
|
2010-01-31 02:33:27 +08:00
|
|
|
/* HOME key */
|
2009-11-06 07:59:01 +08:00
|
|
|
rt_kprintf("key_home\n");
|
|
|
|
kbd_event.key = RTGUIK_HOME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf("key_enter\n");
|
|
|
|
kbd_event.key = RTGUIK_RETURN;
|
|
|
|
}
|
|
|
|
}
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2009-11-06 07:59:01 +08:00
|
|
|
if ( key_down_GETVALUE() == 0 )
|
|
|
|
{
|
|
|
|
rt_kprintf("key_down\n");
|
|
|
|
kbd_event.key = RTGUIK_DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( key_up_GETVALUE() == 0 )
|
|
|
|
{
|
|
|
|
rt_kprintf("key_up\n");
|
|
|
|
kbd_event.key = RTGUIK_UP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( key_right_GETVALUE() == 0 )
|
|
|
|
{
|
|
|
|
rt_kprintf("key_right\n");
|
|
|
|
kbd_event.key = RTGUIK_RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( key_left_GETVALUE() == 0 )
|
|
|
|
{
|
|
|
|
rt_kprintf("key_left\n");
|
|
|
|
kbd_event.key = RTGUIK_LEFT;
|
|
|
|
}
|
2010-01-31 02:33:27 +08:00
|
|
|
|
|
|
|
if (kbd_event.key != RTGUIK_UNKNOWN)
|
|
|
|
{
|
|
|
|
/* post down event */
|
|
|
|
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
|
|
|
|
|
|
|
next_delay = 10;
|
|
|
|
/* delay to post up event */
|
|
|
|
rt_thread_delay(next_delay);
|
|
|
|
|
|
|
|
/* post up event */
|
|
|
|
kbd_event.type = RTGUI_KEYUP;
|
|
|
|
rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
|
|
|
|
}
|
2009-11-06 07:59:01 +08:00
|
|
|
|
|
|
|
/* wait next key press */
|
|
|
|
rt_thread_delay(next_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 03:47:12 +08:00
|
|
|
void rt_hw_key_init(void)
|
2009-11-06 07:59:01 +08:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|