概述
1、代码如下
/*
* drivershidusbhidusbmouse.c
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
/* USB Device ID */
#define USB_VENDOR_ID_AIC 0xA69C
#ifndef CONFIG_USB_BT
#define USB_PRODUCT_ID_AIC 0x8800
#else
#define USB_PRODUCT_ID_AIC 0x8801
#endif
static struct usb_device_id aicwf_usb_id_table[] = {
//{USB_DEVICE(0x8801,0x8800)},
//{ } /* Terminating entry */
#ifndef CONFIG_USB_BT
{USB_DEVICE(USB_VENDOR_ID_AIC, USB_PRODUCT_ID_AIC)},
#else
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_AIC, USB_PRODUCT_ID_AIC, 0xff, 0xff, 0xff)},
#endif
{}
};
static int usbmouse_as_key_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev(intf);
printk("found usbmouse!n");
printk("bcdUSB = %xn", dev->descriptor.bcdUSB);
printk("VID = 0x%xn", dev->descriptor.idVendor);
printk("PID = 0x%xn", dev->descriptor.idProduct);
return 0;
}
static void usbmouse_as_key_disconnect(struct usb_interface *intf)
{
printk("disconnect usbmouse!n");
}
/* 1. 分配/设置usb_driver */
static struct usb_driver usbmouse_as_key_driver = {
.name = "usbmouse_as_key_",
.probe = usbmouse_as_key_probe,
.disconnect = usbmouse_as_key_disconnect,
.id_table = aicwf_usb_id_table,
};
static int usbmouse_as_key_init(void)
{
/* 2. 注册 */
usb_register(&usbmouse_as_key_driver);
return 0;
}
static void usbmouse_as_key_exit(void)
{
usb_deregister(&usbmouse_as_key_driver);
}
module_init(usbmouse_as_key_init);
module_exit(usbmouse_as_key_exit);
MODULE_LICENSE("GPL");
2、insmod 加载usbmouse_as_key.ko
dmesg 信息说明加载成功
[ 3928.470862] found usbmouse!
[ 3928.470888] bcdUSB = 200
[ 3928.470909] VID = 0xa69c
[ 3928.470926] PID = 0x8800
[ 3928.471201] kobject: 'drivers' (88a095c0): kobject_add_internal: parent: 'usbmouse_as_key', set: '<NULL>'
[ 3928.471372] kobject: 'usbmouse_as_key_' (887cfe80): kobject_uevent_env
[ 3928.471433] kobject: 'usbmouse_as_key_' (887cfe80): fill_kobj_path: path = '/bus/usb/drivers/usbmouse_as_key_'
[ 3928.474580] usbcore: registered new interface driver usbmouse_as_key_
最后
以上就是痴情西装为你收集整理的usb驱动程序实现的全部内容,希望文章能够帮你解决usb驱动程序实现所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复