Annotation of kernel/bsd/dev/ppc/drvUSBCMD/mouse/HIDEmulation.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*
        !            26:        File:           HIDEmulation.c
        !            27: 
        !            28:        Contains:       HID Emulation glue code between the ADB SHIM and the USB Mouse HID Module
        !            29: 
        !            30:        Version:        xxx put version here xxx
        !            31: 
        !            32:        Copyright:      � 1998 by Apple Computer, Inc., all rights reserved.
        !            33: 
        !            34:        File Ownership:
        !            35: 
        !            36:                DRI:                            Craig Keithley
        !            37: 
        !            38:                Other Contact:          xxx put other contact here xxx
        !            39: 
        !            40:                Technology:                     xxx put technology here xxx
        !            41: 
        !            42:        Writers:
        !            43: 
        !            44:                (BWS)   Brent Schorsch
        !            45:                (DKF)   David Ferguson
        !            46:                (CJK)   Craig Keithley
        !            47: 
        !            48:        Change History (most recent first):
        !            49: 
        !            50:         <USB30>          7/6/98        CJK             make certain cursor device is removed when interrupt is
        !            51:                                                                        installed
        !            52:         <USB29>         6/22/98        CJK             move cursordevice setup to InterfaceEntry, which is guarenteed
        !            53:                                                                        to be called at task time
        !            54:         <USB28>         6/18/98        BWS             fixed interrupt refcon support
        !            55:         <USB27>         6/18/98        CJK             add interrupt refcon support
        !            56:         <USB26>         5/28/98        CJK             remove pragma unused from NotifyRegisteredHIDUser
        !            57:         <USB25>         5/20/98        CJK             change driver name from USBMouseModule to USBHIDMouseModule
        !            58:         <USB24>         5/13/98        CJK             move DPI setting to interface entry code
        !            59:         <USB23>         4/24/98        CJK             add "get device units per inch" functionality
        !            60:         <USB22>         4/23/98        CJK             add status message when interrupt is installed.
        !            61:         <USB21>         4/23/98        CJK             Reworked mouse functionality to always pass mouse data on to the
        !            62:                                                                        register HID user (even if the data is the same as the last
        !            63:                                                                        read).
        !            64:         <USB20>         4/20/98        CJK             add in mouse demo mode control selector
        !            65:         <USB19>          4/9/98        CJK             remove include of USBClassDrivers.h, USBHIDModules.h, and
        !            66:                                                                        USBDeviceDefines.h
        !            67:         <USB18>          4/9/98        CJK             remove demo mode support
        !            68:                <17>      4/8/98        CJK             rework USBMouseIn to work the same way as the standard interrupt
        !            69:                                                                        handler
        !            70:                <16>     3/27/98        CJK             only set units per inch to 100 when using a BTC keyboard.
        !            71:                <15>     3/25/98        CJK             Move units per inch initialization to here, as we're now using
        !            72:                                                                        interrupt transactions. Remove clip to -90. Change name of
        !            73:                                                                        paramblock pointer to better indicate that it's a pointer to a
        !            74:                                                                        cursor device manager struct.
        !            75:                <14>     3/18/98        CJK             Add back in the clip to -90. Seems that this is the cause of the
        !            76:                                                                        mouse skip.
        !            77:                <13>     3/18/98        CJK             Remove checks for X & Y deltas of less than -90
        !            78:                <12>     3/17/98        CJK             Replace some "};" with just "}" (MetroWerks has a problem with
        !            79:                                                                        it). Add parens around the pragma unused variables. Move
        !            80:                                                                        function prototypes to MouseModule.h
        !            81:                <11>      3/9/98        CJK             Add check for BTC mouse port. If that's the mouse we're using,
        !            82:                                                                        then set the DPI to 100.
        !            83:                <10>      3/3/98        CJK             change cursor device manager device creation to used 'Fixed'
        !            84:                                                                        data type properly.
        !            85:                 <9>      3/2/98        CJK             add check for illegal mouse movement values.  Don't allow
        !            86:                                                                        movement if it's less than negative 90.
        !            87:                 <8>      3/2/98        CJK             Add include of USBHIDModules.h. Remove include of HIDEmulation.h
        !            88:                 <7>     2/18/98        CJK             change call to mouse buttons to only pass a char.
        !            89:          <USB6>         2/17/98        DKF             Add mouse movement if there is no shim installed
        !            90:                 <5>     2/10/98        CJK             change hid notification code to munge X & Y delta values into
        !            91:                                                                        signed 16 bit values.
        !            92:                 <4>     2/10/98        CJK             remove debugstr (that is hit when both mouse buttons are
        !            93:                                                                        pressed).
        !            94:                 <3>     2/10/98        CJK             Remove keyboard related code
        !            95:                 <2>      2/9/98        CJK             remove get descriptor from HID Emulation code
        !            96:                 <1>      2/9/98        CJK             First time check in.  Cloned from CompoundDriver.
        !            97: */
        !            98: 
        !            99: //#include <Types.h>
        !           100: //#include <Devices.h>
        !           101: #include "../driverservices.h"
        !           102: //#include <CursorDevices.h>
        !           103: #include "../USB.h"
        !           104: #include "MouseModule.h"
        !           105: 
        !           106: extern usbMousePBStruct myMousePB;
        !           107: extern void mouse_adbhandler(int number, unsigned char *buffer, int count, void * ssp);
        !           108: 
        !           109: 
        !           110: void USBMouseIn(UInt32 refcon, void * theData)
        !           111: {
        !           112: #pragma unused (refcon)
        !           113: 
        !           114: USBHIDDataPtr  pMouseData;
        !           115: static UInt16  oldbuttons = 0;
        !           116: UInt16         changedbuttons = 0;
        !           117: 
        !           118: //     DebugStr("In USBMouseIn");
        !           119:        pMouseData = (USBHIDDataPtr)theData;
        !           120: 
        !           121:        // Tell the Cursor Device Manager that we moved
        !           122:        if ((pMouseData->mouse.XDelta != 0) || (pMouseData->mouse.YDelta !=0))
        !           123:        {
        !           124:                CursorDeviceMove(myMousePB.pCursorDeviceInfo, pMouseData->mouse.XDelta, pMouseData->mouse.YDelta);
        !           125:        }
        !           126:        
        !           127:        // Update with the state of the buttons.
        !           128:        pMouseData->mouse.buttons &= 0x07;
        !           129:        changedbuttons = oldbuttons ^ pMouseData->mouse.buttons;
        !           130:        if (changedbuttons)
        !           131:        {
        !           132:                CursorDeviceButtons(myMousePB.pCursorDeviceInfo, (short)pMouseData->mouse.buttons);
        !           133:        }
        !           134:        oldbuttons = pMouseData->mouse.buttons;
        !           135: }
        !           136: 
        !           137: OSStatus USBHIDInstallInterrupt(HIDInterruptProcPtr HIDInterruptFunction, UInt32 refcon)
        !           138: {
        !           139:        USBExpertStatus(myMousePB.deviceRef, "USBHIDMouseModule: Demo Mode Disabled (interrupt service routine installed)", myMousePB.deviceRef);
        !           140:        myMousePB.interruptRefcon = refcon;
        !           141:        myMousePB.pSHIMInterruptRoutine = HIDInterruptFunction;
        !           142:        if (myMousePB.pCursorDeviceInfo != 0)
        !           143:        {
        !           144:                CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
        !           145:                myMousePB.pCursorDeviceInfo = 0;
        !           146:        }
        !           147:        return noErr;
        !           148: }
        !           149: 
        !           150: OSStatus USBHIDPollDevice(void)
        !           151: {
        !           152:        return kUSBInternalErr;
        !           153: }
        !           154: 
        !           155: OSStatus USBHIDControlDevice(UInt32 theControlSelector, void * theControlData)
        !           156: {
        !           157: #pragma unused (theControlData)
        !           158: 
        !           159:        switch (theControlSelector)
        !           160:        {
        !           161:                case kHIDRemoveInterruptHandler:
        !           162:                        myMousePB.interruptRefcon = nil;
        !           163:                        myMousePB.pSavedInterruptRoutine = nil;
        !           164:                        myMousePB.pSHIMInterruptRoutine = nil;
        !           165:                        break;
        !           166:                        
        !           167:                case kHIDEnableDemoMode:
        !           168:                        USBExpertStatus(myMousePB.deviceRef, "USBHIDMouseModule: Demo Mode Enabled", myMousePB.deviceRef);
        !           169:                        
        !           170:                        if (myMousePB.pCursorDeviceInfo == 0)
        !           171:                        {
        !           172:                                myMousePB.pCursorDeviceInfo = &myMousePB.cursorDeviceInfo;
        !           173:                                CursorDeviceNewDevice(&myMousePB.pCursorDeviceInfo);
        !           174:                                
        !           175:                                CursorDeviceSetAcceleration(myMousePB.pCursorDeviceInfo, (Fixed)(1<<16));
        !           176:                                
        !           177:                                CursorDeviceSetButtons(myMousePB.pCursorDeviceInfo, 3);                 // should actually be set by reading
        !           178:                                                                                                                                                                // the HID descriptor, but lacking
        !           179:                                                                                                                                                                // a parser, we'll just force it
        !           180:                                                                                                                                                                // this way.
        !           181:                                CursorDeviceButtonOp(myMousePB.pCursorDeviceInfo, 0, kButtonSingleClick, 0L);
        !           182:                                CursorDeviceButtonOp(myMousePB.pCursorDeviceInfo, 1, kButtonSingleClick, 0L);
        !           183:                                CursorDeviceButtonOp(myMousePB.pCursorDeviceInfo, 2, kButtonSingleClick, 0L);
        !           184:                                CursorDeviceUnitsPerInch(myMousePB.pCursorDeviceInfo, (Fixed)(myMousePB.unitsPerInch));
        !           185:                        }
        !           186:                
        !           187:                        myMousePB.pSavedInterruptRoutine = myMousePB.pSHIMInterruptRoutine;
        !           188:                        myMousePB.pSHIMInterruptRoutine = USBMouseIn;
        !           189:                        break;
        !           190: 
        !           191:                case kHIDDisableDemoMode:
        !           192:                        USBExpertStatus(myMousePB.deviceRef, "USBHIDMouseModule: Demo Mode Disabled", myMousePB.deviceRef);
        !           193:                        if (myMousePB.pCursorDeviceInfo != 0)
        !           194:                        {
        !           195:                                CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
        !           196:                                myMousePB.pCursorDeviceInfo = 0;
        !           197:                        }
        !           198:                        myMousePB.pSHIMInterruptRoutine = myMousePB.pSavedInterruptRoutine;
        !           199:                        break;
        !           200: 
        !           201:                default:
        !           202:                        return paramErr;
        !           203:        }
        !           204:        return noErr;
        !           205: }
        !           206: 
        !           207: 
        !           208: 
        !           209: OSStatus USBHIDGetDeviceInfo(UInt32 theInfoSelector, void * theInfo)
        !           210: {
        !           211: HIDInterruptProcPtr * pHIDIntProcPtr;
        !           212: UInt32 * pUnits;
        !           213: UInt32 * pInterruptRefcon;
        !           214: 
        !           215:        switch (theInfoSelector)
        !           216:        {
        !           217:                case kHIDGetDeviceUnitsPerInch:
        !           218:                        pUnits = (UInt32*)theInfo;
        !           219:                        *pUnits = (UInt32)(myMousePB.unitsPerInch);
        !           220:                        break;
        !           221:                        
        !           222:                        
        !           223:                case kHIDGetInterruptHandler:
        !           224:                        pHIDIntProcPtr = (HIDInterruptProcPtr *)theInfo;     
        !           225:                        *pHIDIntProcPtr = myMousePB.pSHIMInterruptRoutine;
        !           226:                        break;
        !           227: 
        !           228:                case kHIDGetInterruptRefcon:
        !           229:                        pInterruptRefcon = (UInt32 *)theInfo;
        !           230:                        *pInterruptRefcon = myMousePB.interruptRefcon;
        !           231:                        break;
        !           232:                
        !           233:                default:
        !           234:                        return paramErr;
        !           235:        }
        !           236:        return noErr;
        !           237: }
        !           238: 
        !           239: OSStatus USBHIDEnterPolledMode(void)
        !           240: {
        !           241:        return unimpErr;
        !           242: }
        !           243: 
        !           244: OSStatus USBHIDExitPolledMode(void)
        !           245: {
        !           246:        return unimpErr;
        !           247: }
        !           248: 
        !           249: void NotifyRegisteredHIDUser(UInt32 devicetype, UInt8 hidReport[])
        !           250: {
        !           251: #pragma unused (devicetype)
        !           252: 
        !           253: USBHIDData             theMouseData;
        !           254: SInt8                  myXDelta, myYDelta;
        !           255: UInt8                  adb_data[4];
        !           256: 
        !           257:        theMouseData.mouse.buttons = (UInt16)hidReport[0];
        !           258:        
        !           259:        myXDelta = (SInt8)hidReport[1];
        !           260:        myYDelta = (SInt8)hidReport[2];  
        !           261: //kprintf("***Mouse data: buttons=0x%x, Xdelta=0x%x, YDelta=0x%x***\n",hidReport[0],hidReport[1],hidReport[2]);
        !           262:        theMouseData.mouse.XDelta = (SInt16)myXDelta;
        !           263:        theMouseData.mouse.YDelta = (SInt16)myYDelta;
        !           264:        
        !           265:        //A.W. call the mouse driver in ADB-land
        !           266:        adb_data[0] = (SInt8)hidReport[2];
        !           267:        adb_data[1] = (SInt8)hidReport[1];
        !           268:        if (hidReport[0] == 1)   /* Clicked */
        !           269:        {
        !           270:                adb_data[0] = ((adb_data[0] >>1) & 0x7f);    
        !           271:        }
        !           272:        else adb_data[0] = 0x80 | (adb_data[0] >>1);  //button 1 clickif (hidReport[0] == 2)
        !           273: 
        !           274:        if (hidReport[0] == 2)   /* Clicked */
        !           275:        {
        !           276:                adb_data[1] = ((adb_data[1] >>1) & 0x7f);    
        !           277:        }
        !           278:        else adb_data[1] = 0x80 | (adb_data[1] >>1);  //button 1 clickif (hidReport[0] == 2)
        !           279: 
        !           280:        mouse_adbhandler(3, adb_data, 2, (void *) 0);
        !           281: 
        !           282:        if (myMousePB.pSHIMInterruptRoutine)
        !           283:        {
        !           284:                (*myMousePB.pSHIMInterruptRoutine)(myMousePB.interruptRefcon, (void *)&theMouseData);
        !           285:        }
        !           286: }
        !           287: USBHIDModuleDispatchTable TheHIDModuleDispatchTable =
        !           288: {
        !           289:        (UInt32)0,
        !           290:        (USBHIDInstallInterruptProcPtr)USBHIDInstallInterrupt,
        !           291:        (USBHIDPollDeviceProcPtr)USBHIDPollDevice,
        !           292:        (USBHIDControlDeviceProcPtr)USBHIDControlDevice,
        !           293:        (USBHIDGetDeviceInfoProcPtr)USBHIDGetDeviceInfo,
        !           294:        (USBHIDEnterPolledModeProcPtr)USBHIDEnterPolledMode,
        !           295:        (USBHIDExitPolledModeProcPtr)USBHIDExitPolledMode
        !           296: };
        !           297: CursorDevicePtr gUSBMouse;
        !           298: CursorDevice   ourDevice;
        !           299: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.