key设备仿真原理
一. key按键UI添加
QEMU是不提供按键UI的,所以我们要先添加key UI图片。如下可以看到,我们画了四个按键,所对应的x,y相对坐标,长,宽和状态,在按键初始化的时候先去显示初始状态下的UI,但是只对应了两个pin脚GPIO05_01和GPIO01_18;
\qemu\ui\button_ui.c
/*
* button1 : GPIO05_01
* button2 : GPIO01_18
*
*/
static int pin_to_button_map[][3] = {
/* group, pin, button(0-button1, 1-button2) */
{5, 1, 0},
{1, 18, 1},
};
typedef struct button_desc {
int x;
int y;
int w;
int h;
int pressed;
}button_desc;
static struct button_desc buttons_desc[] = {
{14, 18, 56, 56, 0},
{85, 18, 56, 56, 0},
{157, 18, 56, 56, 0},
{228, 18, 56, 56, 0},
{},
};
static int button_ui_backgroud_prepare(DeviceState *dev)
{
...
/* /..../bin/../etc/xxx.bmp */
sprintf(tFileMapButtons.strFileName, "%s/../etc/buttons.bmp", cur_app_abs_dir);
sprintf(tFileMapButtonPressed.strFileName, "%s/../etc/button_pressed.bmp", cur_app_abs_dir);
err = MapFile(&tFileMapButtons);
err |= MapFile(&tFileMapButtonPressed);
if (err)
return -1;
button_mem_pixels.iBpp = 32; /* PIXMAN_x8r8g8b8 */
err = pBMPParser->GetPixelDatas(&tFileMapButtons, &button_mem_pixels);
button_pressed_pixels.iBpp = 32; /* PIXMAN_x8r8g8b8 */
err |= pBMPParser->GetPixelDatas(&tFileMapButtonPressed, &button_pressed_pixels);
x = bs->bd[0].x;
y = bs->bd[0].y;
pBMPParser->CopyRegionPixelDatas(&button_released_pixels, &button_mem_pixels, x, y, button_pressed_pixels.iWidth, button_pressed_pixels.iHeight);
UnMapFile(&tFileMapButtons);
UnMapFile(&tFileMapButtonPressed);
return err;
}

二. key按键设备添加
设备注册常用框架,可以看到在设备初始化函数里对按键UI的初始化创建。
\qemu\hw\gpio\100ask_imx6ull_buttons.