Annotation of XNU/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBMouse.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * 18 June 1998          Start IOKit version.
        !            24:  * 18 Nov  1998 suurballe port to C++
        !            25:  *  4 Oct  1999 decesare  Revised for Type 4 support and sub-classed drivers.
        !            26:  *  1 Feb  2000 tsherman  Added extended mouse functionality (implemented in setParamProperties)
        !            27:  */
        !            28: 
        !            29: #include "AppleADBMouse.h"
        !            30: #include <IOKit/hidsystem/IOHIDTypes.h>
        !            31: #include <IOKit/IOLib.h>
        !            32: 
        !            33: // ****************************************************************************
        !            34: // NewMouseData
        !            35: //
        !            36: // ****************************************************************************
        !            37: static void NewMouseData(IOService * target, UInt8 adbCommand, IOByteCount length, UInt8 * data)
        !            38: {
        !            39:   ((AppleADBMouse *)target)->packet(adbCommand, length, data);
        !            40: }
        !            41: 
        !            42: 
        !            43: // ****************************************************************************
        !            44: 
        !            45: #undef super
        !            46: #define super IOHIPointing
        !            47: 
        !            48: OSDefineMetaClassAndStructors(AppleADBMouse, IOHIPointing);
        !            49: 
        !            50: 
        !            51: // ****************************************************************************
        !            52: // probe
        !            53: //
        !            54: // ****************************************************************************
        !            55: IOService * AppleADBMouse::probe(IOService * provider, SInt32 * score)
        !            56: {
        !            57:   adbDevice = (IOADBDevice *)provider;
        !            58:   
        !            59:   return this;
        !            60: }
        !            61: 
        !            62: 
        !            63: // ****************************************************************************
        !            64: // start
        !            65: //
        !            66: // ****************************************************************************
        !            67: bool AppleADBMouse::start(IOService * provider)
        !            68: {
        !            69:   if(!super::start(provider)) return false;
        !            70:   
        !            71:   if(!adbDevice->seizeForClient(this, NewMouseData)) {
        !            72:     IOLog("%s: Seize failed\n", getName());
        !            73:     return false;
        !            74:   }
        !            75:   
        !            76:   return true;
        !            77: }
        !            78: 
        !            79: 
        !            80: // ****************************************************************************
        !            81: // interfaceID
        !            82: //
        !            83: // ****************************************************************************
        !            84: UInt32 AppleADBMouse::interfaceID(void)
        !            85: {
        !            86:   return NX_EVS_DEVICE_INTERFACE_ADB;
        !            87: }
        !            88: 
        !            89: 
        !            90: // ****************************************************************************
        !            91: // deviceType
        !            92: //
        !            93: // ****************************************************************************
        !            94: UInt32 AppleADBMouse::deviceType ( void )
        !            95: {
        !            96:   return adbDevice->handlerID();
        !            97: }
        !            98: 
        !            99: 
        !           100: // ****************************************************************************
        !           101: // resolution
        !           102: //
        !           103: // ****************************************************************************
        !           104: IOFixed AppleADBMouse::resolution(void)
        !           105: {
        !           106:   return _resolution;
        !           107: }
        !           108: 
        !           109: 
        !           110: // ****************************************************************************
        !           111: // buttonCount
        !           112: //
        !           113: // ****************************************************************************
        !           114: IOItemCount AppleADBMouse::buttonCount(void)
        !           115: {
        !           116:   return _buttonCount;
        !           117: }
        !           118: 
        !           119: 
        !           120: // ****************************************************************************
        !           121: // packet
        !           122: //
        !           123: // ****************************************************************************
        !           124: void AppleADBMouse::packet(UInt8 /*adbCommand*/,
        !           125:                           IOByteCount /*length*/, UInt8 * data)
        !           126: {
        !           127:   int            dx, dy;
        !           128:   UInt32          buttonState = 0;
        !           129:   AbsoluteTime    now;
        !           130:   
        !           131:   dy = data[0] & 0x7f;
        !           132:   dx = data[1] & 0x7f;
        !           133:   
        !           134:   if (dy & 0x40) dy |= 0xffffffc0;
        !           135:   if (dx & 0x40) dx |= 0xffffffc0;
        !           136:   
        !           137:   if ((data[0] & 0x80) == 0) buttonState |= 1;
        !           138:   
        !           139:   clock_get_uptime(&now);
        !           140:   dispatchRelativePointerEvent(dx, dy, buttonState, now);
        !           141: }
        !           142: 
        !           143: 
        !           144: // ****************************************************************************
        !           145: // accelerationTable
        !           146: //
        !           147: // ****************************************************************************
        !           148: void AppleADBMouse::accelerationTable(IOHIAccelerationPoint ** table,
        !           149:                                      IOItemCount * numEntries)
        !           150: {
        !           151:   static IOHIAccelerationPoint defaultTable[] = {
        !           152:     { 0x0000000, 0x000000 },
        !           153:     { 0x000713b, 0x006000 },
        !           154:     { 0x0010000, 0x010000 },
        !           155:     { 0x0044ec5, 0x108000 },
        !           156:     { 0x00c0000, 0x5f0000 },
        !           157:     { 0x016ec4f, 0x8b0000 },
        !           158:     { 0x01d3b14, 0x948000 },
        !           159:     { 0x0227627, 0x960000 },
        !           160:     { 0x7ffffff, 0x960000 }
        !           161:   };
        !           162: 
        !           163:   *table = defaultTable;
        !           164:   *numEntries = sizeof(defaultTable) / sizeof(defaultTable[0]);
        !           165: }
        !           166: 
        !           167: // ****************************************************************************
        !           168: // setParamProperties
        !           169: //
        !           170: // ****************************************************************************
        !           171: IOReturn AppleADBMouse::setParamProperties( OSDictionary * dict )
        !           172: {
        !           173:     OSData *   data;
        !           174:     IOReturn   err = kIOReturnSuccess;
        !           175:     UInt8       adbdata[8];
        !           176:     IOByteCount adblength = 8;
        !           177: 
        !           178:     adbDevice->readRegister(2, adbdata, &adblength);
        !           179: 
        !           180:     if( (data = OSDynamicCast( OSData, dict->getObject("Clicking"))))
        !           181:     {
        !           182:         adbdata[0] = (adbdata[0] & 0x7F) | (*( (UInt8 *) data->getBytesNoCopy() ))<<7;
        !           183:         setProperty("Clicking", (unsigned long long)((adbdata[0]&0x80)>>7), sizeof(adbdata[0])*8);
        !           184:     }
        !           185: 
        !           186:     if( (data = OSDynamicCast( OSData, dict->getObject("Dragging"))))
        !           187:     {
        !           188:         adbdata[1] = (adbdata[1] & 0x7F) | (*( (UInt8 *) data->getBytesNoCopy() ))<<7;
        !           189:         setProperty("Dragging", (unsigned long long)((adbdata[1]&0x80)>>7), sizeof(adbdata[1])*8);
        !           190:     }
        !           191:     
        !           192:     if( (data = OSDynamicCast( OSData, dict->getObject("DragLock"))))
        !           193:     {
        !           194:         adbdata[3] = *((UInt8 *) data->getBytesNoCopy());
        !           195: 
        !           196:         if(adbdata[3])
        !           197:         {
        !           198:             setProperty("DragLock", (unsigned long long)adbdata[3], sizeof(adbdata[3])*8);
        !           199:             adbdata[3] = (0x80 | 127);
        !           200:         }
        !           201:         else
        !           202:         {
        !           203:             setProperty("DragLock", (unsigned long long)adbdata[3], sizeof(adbdata[3])*8);
        !           204:             adbdata[3] = (0x80 | 50) ;
        !           205:         }
        !           206:     }
        !           207:     
        !           208:     adbDevice->writeRegister(2, adbdata, &adblength);
        !           209: 
        !           210:     return( err );
        !           211: }
        !           212: 
        !           213: // ****************************************************************************
        !           214: 
        !           215: #undef super
        !           216: #define super AppleADBMouse
        !           217: 
        !           218: OSDefineMetaClassAndStructors(AppleADBMouseType1, AppleADBMouse);
        !           219: 
        !           220: IOService * AppleADBMouseType1::probe(IOService * provider, SInt32 * score)
        !           221: {
        !           222:   if (!super::probe(provider, score)) return 0;
        !           223:   
        !           224:   return this;
        !           225: }
        !           226: 
        !           227: bool AppleADBMouseType1::start(IOService * provider)
        !           228: {
        !           229:   if (adbDevice->setHandlerID(1) != kIOReturnSuccess) return false;
        !           230:   
        !           231:   _resolution = 100 << 16;
        !           232:   _buttonCount = 1;
        !           233:   
        !           234:   return super::start(provider);
        !           235: }
        !           236: 
        !           237: 
        !           238: // ****************************************************************************
        !           239: 
        !           240: #undef super
        !           241: #define super AppleADBMouse
        !           242: 
        !           243: OSDefineMetaClassAndStructors(AppleADBMouseType2, AppleADBMouse);
        !           244: 
        !           245: IOService * AppleADBMouseType2::probe(IOService * provider, SInt32 * score)
        !           246: {
        !           247:   if (!super::probe(provider, score)) return 0;
        !           248:   
        !           249:   if (adbDevice->setHandlerID(2) != kIOReturnSuccess) return 0;
        !           250:   
        !           251:   return this;
        !           252: }
        !           253: 
        !           254: bool AppleADBMouseType2::start(IOService * provider)
        !           255: {
        !           256:   if (adbDevice->setHandlerID(2) != kIOReturnSuccess) return false;
        !           257:   
        !           258:   _resolution = 200 << 16;
        !           259:   _buttonCount = 1;
        !           260:   
        !           261:   return super::start(provider);
        !           262: }
        !           263: 
        !           264: 
        !           265: // ****************************************************************************
        !           266: 
        !           267: #undef super
        !           268: #define super AppleADBMouse
        !           269: 
        !           270: OSDefineMetaClassAndStructors(AppleADBMouseType4, AppleADBMouse);
        !           271: 
        !           272: IOService * AppleADBMouseType4::probe(IOService * provider, SInt32 * score)
        !           273: {
        !           274:   UInt8       data[8];
        !           275:   IOByteCount length;
        !           276:   
        !           277:   if (!super::probe(provider, score)) return 0;
        !           278:   
        !           279:   if (adbDevice->setHandlerID(4) != kIOReturnSuccess) {
        !           280:     adbDevice->setHandlerID(adbDevice->defaultHandlerID());
        !           281:     return 0;
        !           282:   }
        !           283:   
        !           284:   // To be a Type 4 Extended Mouse, register 1 must return 8 bytes.
        !           285:   if (adbDevice->readRegister(1, data, &length) != kIOReturnSuccess) return 0;
        !           286:   if (length != 8) return 0;
        !           287:   
        !           288:   // Save the device's Extended Mouse Info.
        !           289:   deviceSignature  = ((UInt32 *)data)[0];
        !           290:   deviceResolution = ((UInt16 *)data)[2];
        !           291:   deviceClass      = data[6];
        !           292:   deviceNumButtons = data[7];
        !           293:   
        !           294:   return this;
        !           295: }
        !           296: 
        !           297: bool AppleADBMouseType4::start(IOService * provider)
        !           298: {
        !           299:   UInt8       adbdata[8];
        !           300:   IOByteCount adblength = 8;
        !           301: 
        !           302:   if (adbDevice->setHandlerID(4) != kIOReturnSuccess) return false;
        !           303:   
        !           304:   _resolution = deviceResolution << 16;
        !           305:   _buttonCount = deviceNumButtons;
        !           306: 
        !           307:   // Put device into Extended Mode.
        !           308:   adbdata[6] = 0xD;
        !           309:   if (adbDevice->writeRegister(1, adbdata, &adblength) != 0) return 0;
        !           310: 
        !           311:   Clicking = FALSE;
        !           312:   Dragging = FALSE;
        !           313:   DragLock = FALSE;
        !           314:   
        !           315:   setProperty("Clicking", (unsigned long long)Clicking, sizeof(Clicking)*8);
        !           316:   setProperty("Dragging", (unsigned long long)Dragging, sizeof(Dragging)*8);
        !           317:   setProperty("DragLock", (unsigned long long)DragLock, sizeof(DragLock)*8);
        !           318: 
        !           319:   adbDevice->readRegister(1, adbdata, &adblength);
        !           320:   IOLog("AppleADBMouseType4 deviceClass = %d (Extended Mode)\n", adbdata[6]);
        !           321: 
        !           322:   // Set ADB Extended Features to default values.
        !           323:   adbdata[0] = 25;
        !           324:   adbdata[1] = 20;
        !           325:   adbdata[2] = 25;
        !           326:   adbdata[3] = 0x80 | (50);
        !           327:   adbdata[4] = 50;
        !           328:   adbdata[5] = 10;
        !           329:   adbdata[6] = 0x1B;
        !           330:   adbdata[7] = 0x50;
        !           331:   adblength = 8;
        !           332: 
        !           333:   adbDevice->writeRegister(2, adbdata, &adblength); 
        !           334: 
        !           335:   return super::start(provider);
        !           336: }
        !           337: 
        !           338: void AppleADBMouseType4::packet(UInt8 /*adbCommand*/, IOByteCount length, UInt8 * data)
        !           339: {
        !           340:   int            dx, dy, cnt, numExtraBytes;
        !           341:   UInt32          buttonState = 0;
        !           342:   AbsoluteTime   now;
        !           343:   
        !           344:   numExtraBytes = length - 2;
        !           345:   
        !           346:   dy = data[0] & 0x7f;
        !           347:   dx = data[1] & 0x7f;
        !           348:   
        !           349:   if ((data[0] & 0x80) == 0) buttonState |= 1;
        !           350:   if ((deviceNumButtons > 1) && ((data[1] & 0x80) == 0)) buttonState |= 2;
        !           351:   
        !           352:   for (cnt = 0; cnt < numExtraBytes; cnt++) {
        !           353:     dy |= ((data[2 + cnt] >> 4) & 7) << (7 + (cnt * 3));
        !           354:     dx |= ((data[2 + cnt])      & 7) << (7 + (cnt * 3));
        !           355:     
        !           356:     if ((deviceNumButtons > (cnt * 2)) && ((data[2 + cnt] & 0x80) == 0))
        !           357:       buttonState |= 4 << (cnt * 2);
        !           358:     if ((deviceNumButtons > (cnt * 2 + 1)) && ((data[2 + cnt] & 0x08) == 0))
        !           359:       buttonState |= 4 << (cnt * 2 + 1);
        !           360:   }
        !           361:   
        !           362:   if (dy & (0x40 << (numExtraBytes * 3)))
        !           363:     dy |= (0xffffffc0 << (numExtraBytes * 3));
        !           364:   if (dx & (0x40 << (numExtraBytes * 3)))
        !           365:     dx |= (0xffffffc0 << (numExtraBytes * 3));
        !           366:   
        !           367:   clock_get_uptime(&now);
        !           368:   dispatchRelativePointerEvent(dx, dy, buttonState, now);
        !           369: }

unix.superglobalmegacorp.com

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