⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse.c

📁 Linux2.4.20针对三星公司的s3c2440内核基础上的一些设备驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * mouse_fd/mouse.c * * Copyright (c) 2000, 2001, 2002 Lineo * Copyright (c) 2001 Hewlett Packard * * By:  *      Stuart Lynne <sl@lineo.com>,  *      Tom Rushworth <tbr@lineo.com>,  *      Bruce Balden <balden@lineo.com> * * Copyright (C) 2002 Toshiba Corporation * * Changes Copyright (c) 2003 MontaVista Software, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *//* * Usage: *	move pointer to right(10) and bottom(20) *		echo "0 10 20" > /proc/driver/mouse_fd *	move pointer to left(10) and top(20) *		echo "0 246 236" > /proc/driver/mouse_fd *	press button 1 *		echo "1 0 00" > /proc/driver/mouse_fd *	press button 2 *		echo "2 0 00" > /proc/driver/mouse_fd *	press button 3 *		echo "4 0 00" > /proc/driver/mouse_fd *	release buttons *		echo "0 0 00" > /proc/driver/mouse_fd */#include <linux/config.h>#include <linux/module.h>#include "../usbd-export.h"#include "../usbd-build.h"#include "../usbd-module.h"MODULE_AUTHOR("sl@lineo.com, tbr@lineo.com, TOSHIBA Corporation");MODULE_LICENSE("GPL");MODULE_DESCRIPTION("USB Device Mouse Function");USBD_MODULE_INFO("mouse_fd 0.1-beta");#ifndef MODULE#undef GET_USE_COUNT#define GET_USE_COUNT(foo) 1#endif#include <linux/init.h>#include <linux/kernel.h>#include <linux/list.h>#include <asm/uaccess.h>#include <linux/netdevice.h>#include <linux/smp_lock.h>#include <linux/ctype.h>#include <linux/timer.h>#include <linux/string.h>#include <linux/proc_fs.h>#include "../usbd.h"#include "../usbd-func.h"#include "../usbd-bus.h"#include "../usbd-debug.h"#include "../usbd-inline.h"#include "../usbd-arch.h"#define MOUSE_PACKET_SIZE 3#define MOUSE_PROC_NAME	"driver/mouse_fd"#if !defined (CONFIG_USBD_VENDORID) && !defined(CONFIG_USBD_MOUSE_VENDORID)        #error No Vendor ID#endif#if !defined (CONFIG_USBD_PRODUCTID) && !defined(CONFIG_USBD_MOUSE_PRODUCTID)        #error No Product ID#endif#if CONFIG_USBD_MOUSE_VENDORID        #undef CONFIG_USBD_VENDORID        #define CONFIG_USBD_VENDORID CONFIG_USBD_MOUSE_VENDORID#endif#if CONFIG_USBD_MOUSE_PRODUCTID        #undef CONFIG_USBD_PRODUCTID        #define CONFIG_USBD_PRODUCTID CONFIG_USBD_MOUSE_PRODUCTID#endif#ifndef CONFIG_USBD_SERIAL_NUMBER_STR        #define CONFIG_USBD_SERIAL_NUMBER_STR           ""#endif#ifdef CONFIG_USBD_SELFPOWERED        #define BMATTRIBUTE BMATTRIBUTE_RESERVED | BMATTRIBUTE_SELF_POWERED        #define BMAXPOWER 0#else        #define BMATTRIBUTE BMATTRIBUTE_RESERVED        #define BMAXPOWER CONFIG_USBD_MAXPOWER#endif/* * setup some default values for pktsizes and endpoint addresses. */#ifndef CONFIG_USBD_MOUSE_INT_PKTSIZE        #define CONFIG_USBD_MOUSE_INT_PKTSIZE             16#endif#ifndef CONFIG_USBD_MOUSE_INT_ENDPOINT    #define CONFIG_USBD_MOUSE_INT_ENDPOINT                3#endif/* * check for architecture specific endpoint configurations */#if     defined(ABS_INT_ADDR)         #warning        #warning USING ABS ENDPOINT INT ADDRESS        #undef CONFIG_USBD_MOUSE_INT_ENDPOINT         #if     ABS_INT_ADDR                #define CONFIG_USBD_MOUSE_INT_ENDPOINT            ABS_INT_ADDR        #endif#elif   defined(MAX_INT_ADDR) && defined(CONFIG_USBD_MOUSE_INT_ENDPOINT) && (CONFIG_USBD_MOUSE_INT_ENDPOINT > MAX_INT_ADDR)        #warning        #warning USING DEFAULT ENDPOINT INT ADDRESS        #undef CONFIG_USBD_MOUSE_INT_ENDPOINT         #define CONFIG_USBD_MOUSE_INT_ENDPOINT            DFL_INT_ADDR#endif#if     defined(MAX_INT_PKTSIZE) && defined(CONFIG_USBD_MOUSE_INT_PKTSIZE) && CONFIG_USBD_MOUSE_INT_PKTSIZE > MAX_INT_PKTSIZE        #warning        #warning OVERIDING ENDPOINT INT PKTSIZE        #undef CONFIG_USBD_MOUSE_INT_PKTSIZE        #define CONFIG_USBD_MOUSE_INT_PKTSIZE             MAX_INT_PKTSIZE#endifstruct usb_mouse_private {    struct usb_device_instance *device;    spinlock_t lock;    __u8 data[MOUSE_PACKET_SIZE];    int data_valid;    int duration;};/* Module Parameters ************************************************************************* */static char *dbg = NULL;static u32 vendor_id;static u32 product_id;MODULE_PARM(dbg, "s");MODULE_PARM(vendor_id, "i");MODULE_PARM(product_id, "i");MODULE_PARM_DESC(dbg, "USB Device Debug options");MODULE_PARM_DESC(vendor_id, "USB Device Vendor ID");MODULE_PARM_DESC(product_id, "USB Device Product ID");/* Debug switches (module parameter "dbg=...") *********************************************** */extern int dbgflg_usbdfd_init;int      dbgflg_usbdfd_ep0;int      dbgflg_usbdfd_usbe;int      dbgflg_usbdfd_tx;static debug_option dbg_table[] = {    {&dbgflg_usbdfd_init,NULL,"init","initialization and termination"},    {&dbgflg_usbdfd_ep0,NULL,"ep0","End Point 0 (setup) packet handling"},    {&dbgflg_usbdfd_usbe,NULL,"usbe","USB events"},    {&dbgflg_usbdfd_tx,NULL,"tx","transmit (to host)"},    {NULL,NULL,NULL,NULL}};#define dbg_init(lvl,fmt,args...) dbgPRINT(dbgflg_usbdfd_init,lvl,fmt,##args)#define dbg_ep0(lvl,fmt,args...) dbgPRINT(dbgflg_usbdfd_ep0,lvl,fmt,##args)#define dbg_usbe(lvl,fmt,args...) dbgPRINT(dbgflg_usbdfd_usbe,lvl,fmt,##args)#define dbg_tx(lvl,fmt,args...) dbgPRINT(dbgflg_usbdfd_tx,lvl,fmt,##args)/* ******************************************************************************************* *//* HID Class descriptions  */static struct usb_endpoint_description mouse_default[] = {    { bEndpointAddress: CONFIG_USBD_MOUSE_INT_ENDPOINT,        bmAttributes: INTERRUPT,        wMaxPacketSize: CONFIG_USBD_MOUSE_INT_PKTSIZE,        bInterval: 0x0a, /* 10ms */        direction: IN,        transferSize: MOUSE_PACKET_SIZE, },};/* HID Class descriptions *//* c.f. HID E.10 Report Descriptor (Mouse) */static __u8 mouse_report_desc[] = {    0x05, 0x01,			// USAGE_PAGE (Generic Desktop)    0x09, 0x02,			// USAGE (Mouse)    0xa1, 0x01,			// COLLECTION (Application)    0x09, 0x01,			//   USAGE (Pointer)    0xa1, 0x00,			//   COLLECTION (Physical)    0x05, 0x09,			//     USAGE_PAGE (Button)    0x19, 0x01,			//     USAGE_MINIMUM (Button 1)    0x29, 0x03,			//     USAGE_MAXIMUM (Button 3)    0x15, 0x00,			//     LOGICAL_MINIMUM (0)    0x25, 0x01,			//     LOGICAL_MAXIMUM (1)    0x95, 0x03,			//     REPORT_COUNT (3)    0x75, 0x01,			//     REPORT_SIZE (1)    0x81, 0x02,			//     INPUT (Data,Variable,Absolute)    0x95, 0x01,			//     REPORT_COUNT (1)    0x75, 0x05,			//     REPORT_SIZE (5)    0x81, 0x01,			//     INPUT (Cnstant)    0x05, 0x01,			//     USAGE_PAGE (Generic Desktop)    0x09, 0x30,			//     USAGE (X)    0x09, 0x31,			//     USAGE (Y)    0x15, 0x81,			//     LOGICAL_MINIMUM (-127)    0x25, 0x7f,			//     LOGICAL_MAXIMUM (127)    0x75, 0x08,			//     REPORT_SIZE (8)    0x95, 0x02,			//     REPORT_COUNT (2)    0x81, 0x06,			//     INPUT (Data,Variable,Relative)    0xc0,			//   END_COLLECTION    0xc0			// END_COLLECTION};static struct usb_class_description mouse_class[] = {    { USB_DT_HID, 0, 0, { hid: {	bcdCDC: CLASS_HID_BCD_VERSION,	bCountryCode: 0,	bDescriptorType: USB_DT_REPORT,	wDescriptorLength: sizeof(mouse_report_desc),	reportDescriptor: mouse_report_desc } }}, };/* Data Interface Alternate description(s) */static __devinitdata struct usb_alternate_description mouse_data_alternate_descriptions[] = {    {   iInterface: "Simple Mouse Data Interface - Int mode",         bAlternateSetting: 0,	classes: sizeof(mouse_class)/sizeof(struct usb_class_description),	class_list: mouse_class,        endpoints: sizeof(mouse_default)/sizeof(struct usb_endpoint_description),        endpoint_list: mouse_default, },};/* Interface description(s) */static __devinitdata struct usb_interface_description mouse_interfaces[] = {    {   iInterface: "Simple Mouse Data Interface",         bInterfaceClass: USB_CLASS_HID,        bInterfaceSubClass: 0x01, /* Keyboard/Mouse */        bInterfaceProtocol: 0x02, /* Mouse:2 */        alternates: sizeof(mouse_data_alternate_descriptions)/sizeof(struct usb_alternate_description),        alternate_list: mouse_data_alternate_descriptions, },};/* Configuration description(s) */struct __devinitdata usb_configuration_description mouse_description[] = {    {   iConfiguration: "USB Simple Mouse Configuration",         bmAttributes: BMATTRIBUTE,        bMaxPower: BMAXPOWER,        interfaces: sizeof(mouse_interfaces)/sizeof(struct usb_interface_description),        interface_list: mouse_interfaces, },};/* Device Description */struct __devinitdata usb_device_description mouse_device_description = {    bDeviceClass:       0,     bDeviceSubClass:    0,    bDeviceProtocol:    0,    idVendor:           CONFIG_USBD_VENDORID,    idProduct:          CONFIG_USBD_PRODUCTID,    iManufacturer:      CONFIG_USBD_MANUFACTURER,    iProduct:           CONFIG_USBD_PRODUCT_NAME,    iSerialNumber:      CONFIG_USBD_SERIAL_NUMBER_STR,};static int mouse_send(struct usb_mouse_private *mouse_private){    int port = 0; // XXX compound device    struct urb *urb;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -