?? mgdrv-ucosii.c
字號:
//====================================================================
// File Name : mgdrv-ucosii.c
//====================================================================
/* 包含MiniGUI的配置頭文件(編譯配置選項) */
#include "MiniGUI_config.h"
/* 包含MiniGUI頭文件 */
#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "control.h"
/* 注意,要跟據驅動SWAP_XY_EN定義來設置這兩個宏 */
#define GUI_LCM_XMAX 320 /* 定義液晶x軸的點數 */
#define GUI_LCM_YMAX 240 /* 定義液晶y軸的點數 */
#define IAL_MOUSE_LEFTBUTTON 4
#define IAL_MOUSE_MIDDLEBUTTON 2
#define IAL_MOUSE_RIGHTBUTTON 1
#define IO1PIN (*((volatile unsigned long *) 0xE0028010))
extern void OSTimeDly(WORD ticks);
// 獨立按鍵,P1口
#define KEY_TAB (1<<23)
#define KEY_ENTER (1<<21)
#define KEY_UP (1<<20)
#define KEY_DOWN (1<<19)
#define KEY_LEFT (1<<18)
#define KEY_RIGHT (1<<22)
#define KEY_ALL (KEY_TAB | KEY_ENTER | KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT)
/* --------------------- For Common IAL Engine ----------------- */
/* Should be implemented if you use common ial engine in MiniGUI */
#define COMM_MOUSEINPUT 0x01 /* 鼠標或觸摸屏事件 */
#define COMM_KBINPUT 0x02 /* 按鍵事件 */
/*
* Waits for input for keyboard and touchpanel.
* If no data, this function should go into sleep;
* when data is available, keyboard or touchpanel driver should wake up
* the task/thread in MiniGUI who call comm_wait_for_input.
*
* Normal implementation make this function sleep on a ucosii semaphore.
* return COMM_MOUSEINPUT or COMM_KBINPUT according to type of the input event.
*/
// 查詢鍵盤或鼠標事件
static unsigned char key_sta=0;
/*
int comm_wait_for_input (void)
{ int i;
// 掃描按鍵,若有按鍵則返回按鍵事件
for(i=0; i<100; i++)
{ if((IO1PIN&KEY_ALL) != KEY_ALL)
{ OSTimeDly(2); // 延時10mS,去抖
if((IO1PIN&KEY_ALL) != KEY_ALL)
{ key_sta = 1;
return(COMM_KBINPUT); // 確定有按鍵接下
}
}
}
if(key_sta==1)
{ key_sta=0;
return(COMM_KBINPUT); // 有按鍵放開
}
OSTimeDly(20); // 沒有外部事件,延時100mS,即每100mS掃描一次按鍵
return 0;
}
*/
static unsigned char mouse_sta=0;
int comm_wait_for_input (void)
{ int i;
// 掃描按鍵,若有按鍵則返回鼠標事件
for(i=0; i<100; i++)
{ if((IO1PIN&KEY_ALL) != KEY_ALL)
{ OSTimeDly(2); // 延時10mS,去抖
if((IO1PIN&KEY_ALL) != KEY_ALL)
{ return(COMM_MOUSEINPUT);
}
}
}
if(mouse_sta==1)
{ mouse_sta=0;
return(COMM_MOUSEINPUT); // 有按鍵放開
}
OSTimeDly(20); // 沒有外部事件,延時100mS,即每100mS掃描一次按鍵
return 0;
}
/*
* Gets touchpanel position and button data.
* x, y : position values
* button : Non-zero value means pen is down.
*/
// 該函數的返回值可以是IAL_MOUSE_LEFTBUTTON(表示左鍵按下)、
// IAL_MOUSE_MIDDLEBUTTON(表示中鍵按下)、IAL_MOUSE_RIGHTBUTTON
// (表示右鍵按下)等值"或"的結果。
// 取得鼠標/觸摸屏的參數
int comm_ts_getdata (int *x, int *y, int *button)
{ unsigned long io_dat;
io_dat = IO1PIN; // 掃描按鍵,然后返回
if((io_dat&KEY_DOWN) == 0)
{ *y = (*y) + 5;
if((*y) > (GUI_LCM_YMAX-1))
{ *y = GUI_LCM_YMAX - 1;
}
return(0);
}
if((io_dat&KEY_UP) == 0)
{ *y = (*y) - 5;
if((*y) < 0)
{ *y = 0;
}
return(0);
}
if((io_dat&KEY_RIGHT) == 0)
{ *x = (*x) + 5;
if((*x) > (GUI_LCM_XMAX-1))
{ *x = GUI_LCM_XMAX-1;
}
return(0);
}
if((io_dat&KEY_LEFT) == 0)
{ *x = (*x) - 5;
if((*x) < 0)
{ *x = 0;
}
return(0);
}
if((io_dat&KEY_ENTER) == 0)
{ mouse_sta = 1;
*button = IAL_MOUSE_LEFTBUTTON;
return(0);
}
if((io_dat&KEY_TAB) == 0)
{ mouse_sta = 1;
*button = IAL_MOUSE_RIGHTBUTTON;
return(0);
}
if(mouse_sta==0)
{ *button = 0;
return(0);
}
return(-1);
}
/*
* Gets keyboard key data.
* key : return MiniGUI scancode of the key.
* key_status : key down or up, non-zero value means down.
*/
// 取得按鍵的參數
int comm_kb_getdata (short *key, short *key_status)
{ unsigned long io_dat;
if(key_sta==1)
{ io_dat = IO1PIN; // 掃描按鍵,然后返回
if((io_dat&KEY_TAB) == 0)
{ *key = SCANCODE_TAB;
*key_status = 1;
return(0);
}
if((io_dat&KEY_ENTER) == 0)
{ *key = SCANCODE_ENTER;
*key_status = 1;
return(0);
}
}
else
{ *key_status = 0; // 按鍵放開
return(0);
}
return(-1);
}
/* --------------------- I/O functions -------------------------- */
// for debug purpose
/* Gets a char from uart */
BYTE drv_uart_get_byte (void)
{
//...
return(0);
}
/* Sends a char to uart */
void drv_uart_send_byte (BYTE ch)
{
//...
}
/* ----------------- Implementation of MiniGUI LCD driver interface --------------- */
#define FB_TYPE_RGB565 1 // RGB565 color format for 16 bpp
#define FB_TYPE_RGB332 2 // RGB332 color format for 8 bpp
struct lcd_info {
short height, width; // Pixels
short bpp; // Depth (bits/pixel)
short type; // pixel type
short rlen; // Length of one raster line in bytes
void *fb; // Frame buffer
};
int drv_lcd_init (void)
{
/* Do LCD initialization here, if you have not. */
return 0;
}
int drv_lcd_getinfo (struct lcd_info *li)
{
/*
* Set LCD information in a lcd_info structure pointed by li
* according to properties of your LCD.
*/
/*
li->width = 320;
li->height = 240;
li->bpp = 16;
li->type = FB_TYPE_RGB565;
li->rlen = 320;
li->fb = (void*)0xc000000;
*/
return 0;
}
/* ------------------- Application entry for uC/OS-II -------------- */
/* for reference only */
/*
* main task of MiniGUI
*/
static void* mg_main_task (void* args)
{
/*
* Enter entry in MiniGUI library
*/
minigui_entry (0, NULL);
while(1)
{ OSTimeDly (50);
}
return NULL;
}
/*
* MiniGUI entry for uC/OS-II
* You can call this function before you call OSStart.
*/
void minigui_app_entry (void)
{
pthread_t main_thread;
/*
* Should initialize heap memory management module first
* before using MiniGUI.
*/
if (ucos2_malloc_init ()) {
fprintf (stderr, "Can not init our own malloc implementation for uC/OS-II.\n");
return;
}
/*
* Should initialize POSIX thread module first
* before using MiniGUI.
*/
if (ucos2_posix_pthread_init ()) {
fprintf (stderr, "Can not init our own pthread implementation for uC/OS-II.\n");
return;
}
/*
* Creating a independent thread for MiniGUI main task is a good idea.
*/
pthread_create (&main_thread, NULL, mg_main_task, NULL);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -