如何通过我的模块与USB设备“通话”?

时间:2019-03-24 01:13:21

标签: driver usb module

我已经编写了用于USB插入的游戏手柄模块。我已经检查过我安装的模块是否成功检测到我的设备,甚至调用了“ probe”方法:

    static struct usb_driver driver =
{
    .name = "Driver#1",
    .id_table = table,
    .probe = probe,
    .disconnect = disconnect,
};

我还编写了特殊的 urb 功能,该功能应与我的设备“交谈”

usb_fill_int_urb(j->irq_in, udev,
             usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), //!
             j->idata, 32, irq_hh,
             j, ep_irq_in->bInterval); 

但是我不明白如何初始化irq_in的操作。我想我需要按一些内容,一些信息应该用j->idata书写。我也做过

usb_submit_urb(j->irq_in, GFP_KERNEL);

但是什么也没发生!为什么? 我的探测功能:

static void irq_hh(struct urb *urb)
{
    struct devicec *j = urb->context;/*В какую структура из всех процессов дб заполнена после приёма данных???*/
        char *data = j->idata;
    printk(KERN_INFO "irq_hh: %s", data);
}

static int probe(struct usb_interface *intf, const struct usb_device_id *id)
{
    struct usb_device *udev; //!
    struct usb_endpoint_descriptor *ep_irq_in;  

    int ep_irq_in_idx, error;
    printk(KERN_INFO "probe...%X",id->idVendor);
    j = kzalloc(sizeof(struct devicec), GFP_KERNEL);
    udev = interface_to_usbdev(intf);
    j->irq_in = usb_alloc_urb(0, GFP_KERNEL); 
    //--------------------------------------
    j->udev = udev;
    j->intf = intf;
    //--------------------------------------
    usb_make_path(udev, j->phys, sizeof(j->phys));
    strlcat(j->phys, "/input101", sizeof(j->phys));
    printk(KERN_INFO "%s",j->phys);

    ep_irq_in_idx = 0;
    ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc;

    usb_fill_int_urb(j->irq_in, udev,
             usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), //!
             j->idata, 32, irq_hh,
             j, ep_irq_in->bInterval); 

    j->irq_in->transfer_dma = j->idata_dma;
    j->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

    error = usb_submit_urb(j->irq_in, GFP_KERNEL);

    printk(KERN_INFO "%d",error);

    return 0;
}

0 个答案:

没有答案