QEMU学习(三):key设备仿真及驱动开发

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值